Marko Taht
Marko Taht

Reputation: 1522

Hyperledger fabric add index to java chaincode

Is it possible to add index to chaincode written in java? Looking at the tutorials and sample projects all is only with GO or JS very little info about java. If i want to add index to asset to i need to write the chaincode in GO?

I have places the META-INF folder everywhere but still no index is created. Im beginning to think that either the depolyCC.sh script cant handle it in case of java or there needs to be something made inside the gradle.build file. What might be the issue and how to fix it ?

EDIT

I read through some opf the deploiment scripts. Seems like for java its looking in the wrong place for META-INF. Since META-INF is in the root of chaingode and gradle does not but it into the build folder, packageChaincode is inside the build dir and never sees META-INF. It feels like i need to modify gradle.build somehow to make the packager see the meta-inf

    elif [ "$CC_SRC_LANGUAGE" = "java" ]; then
  CC_RUNTIME_LANGUAGE=java

  infoln "Compiling Java code..."
  pushd $CC_SRC_PATH
  ./gradlew installDist
  popd
  successln "Finished compiling Java code"
  CC_SRC_PATH=$CC_SRC_PATH/build/install/$CC_NAME



packageChaincode() {
  ORG=$1
  setGlobals $ORG
  set -x
  peer lifecycle chaincode package ${CC_NAME}.tar.gz --path ${CC_SRC_PATH} --lang ${CC_RUNTIME_LANGUAGE} --label ${CC_NAME}_${CC_VERSION} >&log.txt
  res=$?
  { set +x; } 2>/dev/null
  cat log.txt
  verifyResult $res "Chaincode packaging on peer0.org${ORG} has failed"
  successln "Chaincode is packaged on peer0.org${ORG}"

}

Upvotes: 0

Views: 516

Answers (3)

fetulhak abdurahman
fetulhak abdurahman

Reputation: 58

If you are customizing the HLF test network here is what i did:

include the following copy task in build.gradle file found in chaincode-java folder.

task copyTask {
doLast {
    copy {
        from '/home/fetulhak/fabric-samples/asset-transfer-basic/chaincode-java'
        into "/home/fetulhak/fabric-samples/asset-transfer-basic/chaincode-java/build/install/basic"
        include 'META-INF/**'
    }

}

}

Then to run this task go to the deployCC bash script located on test-network folder under scripts folder and add this single line code (./gradlew copyTask build) as shown below. Voilaaa ...that works for me after a long trial and error

    elif [ "$CC_SRC_LANGUAGE" = "java" ]; then
  CC_RUNTIME_LANGUAGE=java

  rm -rf $CC_SRC_PATH/build/install/
  infoln "Compiling Java code..."
  pushd $CC_SRC_PATH
  ./gradlew installDist
  ./gradlew copyTask build
  popd
  successln "Finished compiling Java code"

NB: you have to first create the your couchdb index file and put it under the META-INF folder "/home/fetulhak/fabric-samples/asset-transfer-basic/chaincode-java/META-INF/statedb/couchdb"

Upvotes: 0

Marko Taht
Marko Taht

Reputation: 1522

Found the solution. Basically. gralde installDist placed everything into build/install/basic folder but META-INF was on the root level. When packaging it didnt include the META-INF folder. I added copy command into gradle.build so that it would copy the META-INF folder into the build/install/basic folder. Now when building chaincode it includes the META-INF that is in build/install/basic folder and index is created. It was issue with gradle build.

Upvotes: 2

Calanais
Calanais

Reputation: 1580

Specifying a CouchDB Index for Java is the same as for any other chaincode. Ensure that the same file is placed in the same place in the directory.

META_INF/statedb/couchdb/indexes in the root of the chaincode.

Upvotes: 0

Related Questions