I got this I believe pretty common error "..LedgerError - ResourceNotFound: ledger: resource not found" .
To make it simple, this is what I have:
Try simple chaincode, the given chaincode_example02.go codes
turned off security hence no CA (CORE_SECURITY_ENABLED=false CORE_SECURITY_PRIVACY=falss)
1 peer node only (using 0.5 version), it is a peer docker image
run in dev mode
This is how I deployed the code in dev mode, pls do verify if the cli is correct:
CORE_CHAINCODE_ID_NAME=mycc CORE_PEER_ADDRESS=0.0.0.0:30303 ./chaincode_example02
and it shows
'Received REGISTERED, ready for invocations'
Now trying to query it, pls do verify if this cli is correct :
peer chaincode query -n mycc -c '{"Function": "query", "Args": ["b"]}'
but the error returned were :
Error: Error querying chaincode: rpc error: code = 2 desc = "Error:Failed to launch chaincode spec(Could not get deployment transaction for chaincode_example02 - LedgerError - ResourceNotFound: ledger: resource not found)"
Any idea? I checked all logs under /var but didn't find anything useful, also checked /var/hyperledger and did see some updates under /var/hyperledger/production/db.
This trial seems pretty straight forwards but surprise to get an error.
.. so how should I go about debugging this?
The following command,
CORE_CHAINCODE_ID_NAME=mycc CORE_PEER_ADDRESS=0.0.0.0:30303 ./chaincode_example02
doesn't deploy the chaincode, it simply start and register the chaincode with the validating peer.
Once it is registered, you need todeploy and then invoke it before you can query.
As described here,
First, send a chaincode deploy transaction, only once, to the
validating peer. The CLI connects to the validating peer using the
properties defined in the core.yaml file. Note: The deploy transaction
typically requires a path parameter to locate, build, and deploy the
chaincode. However, because these instructions are specific to local
development mode and the chaincode is deployed manually, the name
parameter is used instead.
peer chaincode deploy -n mycc -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'
Once it is deployed, you can invoke it as many times you want and then query the invoked transaction,
To invoke,
peer chaincode invoke -l golang -n mycc -c '{"Function": "invoke", "Args": ["a", "b", "10"]}'
and to query,
peer chaincode query -l golang -n mycc -c '{"Function": "query", "Args": ["b"]}'
Also make sure that you have peer running in one terminal, running the chaincode in 2nd terminal, while deploying, invoking and querying transactions from the third one.
Related
This question already has answers here:
Tell when Job is Complete
(7 answers)
Closed 3 years ago.
I'm looking for a way to wait for Job to finish execution Successfully once deployed.
Job is being deployed from Azure DevOps though CD on K8S on AWS. It is running one time incremental database migrations using Fluent migrations each time it's deployed. I need to read pod.status.phase field.
If field is "Succeeded", then CD will continue. If it's "Failed", CD stops.
Anyone have an idea how to achieve this?
I think the best approach is to use the kubectl wait command:
Wait for a specific condition on one or many resources.
The command takes multiple resources and waits until the specified
condition is seen in the Status field of every given resource.
It will only return when the Job is completed (or the timeout is reached):
kubectl wait --for=condition=complete job/myjob --timeout=60s
If you don't set a --timeout, the default wait is 30 seconds.
Note: kubectl wait was introduced on Kubernetes v1.11.0. If you are using older versions, you can create some logic using kubectl get with --field-selector:
kubectl get pod --field-selector=status.phase=Succeeded
We can check Pod status using K8S Rest API.
In order to connect to API, we need to get a token:
https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#without-kubectl-proxy
# Check all possible clusters, as you .KUBECONFIG may have multiple contexts:
kubectl config view -o jsonpath='{"Cluster name\tServer\n"}{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}'
# Select name of cluster you want to interact with from above output:
export CLUSTER_NAME="some_server_name"
# Point to the API server refering the cluster name
APISERVER=$(kubectl config view -o jsonpath="{.clusters[?(#.name==\"$CLUSTER_NAME\")].cluster.server}")
# Gets the token value
TOKEN=$(kubectl get secrets -o jsonpath="{.items[?(#.metadata.annotations['kubernetes\.io/service-account\.name']=='default')].data.token}"|base64 -d)
From above code we have acquired TOKEN and APISERVER address.
On Azure DevOps, on your target Release, on Agent Job, we can add Bash task:
#name of K8S Job object we are waiting to finish
JOB_NAME=name-of-db-job
APISERVER=set-api-server-from-previous-code
TOKEN=set-token-from-previous-code
#log APISERVER and JOB_NAME for troubleshooting
echo API Server: $APISERVER
echo JOB NAME: $JOB_NAME
#keep calling API until you get status Succeeded or Failed.
while true; do
#read all pods and query for pod containing JOB_NAME using jq.
#note that you should not have similar pod names with job name otherwise you will get mutiple results. This script is not expecting multiple results.
res=$(curl -X GET $APISERVER/api/v1/namespaces/default/pods/ --header "Authorization: Bearer $TOKEN" --insecure | jq --arg JOB_NAME "$JOB_NAME" '.items[] | select(.metadata.name | contains($JOB_NAME))' | jq '.status.phase')
if (res=="Succeeded"); then
echo Succeeded
exit 0
elif (res=="Failed"); then
echo Failed
exit 1
else
echo $res
fi
sleep 2
done
If Failed, script will exit with code 1 and CD will stop (if configured that way).
If Succeeded, exist with code 0 and CD will continue.
In final setup:
- Script is part of artifact and I'm using it inside Bash task in Agent Job.
- I have placed JOB_NAME into Task Env. Vars so it can be used for multiple DB migrations.
- Token and API Server address are in Variable group on global level.
TODO:
curl is not existing with code 0 if URL is invalid. It needs --fail flag, but still above line exists 0.
"Unknown" Pod status should be handled as well
I am trying to work on my first network in Hyperledger Fabric. Using the following documentation http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html
I have completed the setup till http://hyperledger-fabric.readthedocs.io/en/latest/build_network.html#create-join-channel but when I run the
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
I got hte following error:
Error: Got unexpected status: BAD_REQUEST
In attempt to resolve i follow the solution given at First network in hyperledger but faced error on running
/bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'
I brought my network down using
./bfyn.sh -m down
and bring the network up that gave me following error:
ERROR: for orderer.example.com Cannot start service orderer.example.com: oci runtime error: container_linux.go:265: starting container process caused "process_
linux.go:368: container init caused \"rootfs_linux.go:57: mounting \\"/c/Users/lenovo/fabric-samples/first-network/channel-artifacts/genesis.block\\" to rootfs \\"/mnt/sda1/var/lib/docker/aufs/mnt/16c8954b277dec9a00370bdaa4316db282759b3dd6892ffc25f860a4c9e06d58\\" at\"/mnt/sda1/var/lib/docker/aufs/mnt/16c8954b277dec9a00370bdaa4316db282759b3dd6892ffc25f860a4c9e06d58/var/hyperledger/orderer/orderer.genesis.block\\" caused \\"not a directory\\"\"":Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type ERROR: Encountered errors while bringing up the project.
ERROR !!!! Unable to start network
Error response from daemon: No such container: cli
Delete as admin the channel-artifacts folder, down the network and restart it. Your error must be related to an error at channel-artifacts generation.
You need to be in /c/users when you run the curl command, as documented here.
Continue on with other setup instructions
also, please make sure you run your docker command prompt in administrator mode.
I have started a peer and membersrvc container with docker compose. They have started successfully. I deploying example02 chaincode from CLI (tried REST also). I get a success message. When i try to query the chaincode, i am getting Error when querying chaincode: Error:Failed to launch chaincode spec(Could not get deployment transaction for mycc - LedgerError - ResourceNotFound: ledger: resource not found)"
If you are trying to deploy the chaincode in dev mode, you first need to register the chaincode.
(Registration is only required in dev mode and not for production mode)
To register your chaincode on windows 10 machine in docker container :
open command prompt and go to bash shell using docker command
docker exec -it [peer container id] /bin/bash
Browse to chainocde directory and register it using
CORE_CHAINCODE_ID_NAME=mycc CORE_PEER_ADDRESS=127.0.0.1:7051 ./chaincode_example02
Now you would see register successful message : “Received REGISTERED, ready for invocations” and is ready to deploy, invoke and query in dev mode
Note: Leave the window as with register handler open, closing it would deregister the chaincode.
Waiting for a few minutes after the chaincode deployment might produce different results when querying. As described here, it could take a couple of minutes for chaincode to deploy. Another suggestion mentioned is to review the chaincode container log to determine if there are problems communicating with a peer.
It is also possible that the chaincode deployment was not successful. The log for the peer where the chaincode deployment was initiated could be reviewed to determine if this provides any insight.
There are also a couple of prior posts that are similar and might help.
How to debug chaincode? LedgerError - ResourceNotFound
Hyperledger : Deploying chaincode successful. But, cannot query - says ResourceNotFound
In particular, I have chaincode that is stored on github and I would like to executive this chaincode in my local cluster of notes. What is the easiest way of getting my local cluster to pull down remote chaincode and execute it.
The Hyperledger fabric chaincode deploy CLI command is described here. Essentially, you give it the path to the chaincode on your local filesystem starting at one of the values of the $GOPATH environment variable. For example:
./peer chaincode deploy -p github.com/hyperledger/fabric/example/chaincode/go/chaincode_example02 -c '{"Function":"init", "Args": ["a","100", "b", "200"]}'
As we all know by now, the only way to run tests on iOS is by using the simulator. My problem is that we are running jenkins and the iOS builds are running on a slave (via SSH), as a result running xcodebuild can't start the simulator (as it runs headless). I've read somewhere that it should be possible to get this to work with SimLauncher (gem sim_launcher). But I can't find any info on how to set this up with xcodebuild. Any pointers are welcome.
Headless and xcodebuild do not mix well. Please consider this alternative:
You can configure the slave node to launch via jnlp (webstart). I use a bash script with the .command extension as a login item (System Preferences -> Users -> Login Items) with the following contents:
#!/bin/bash
slave_url="https://gardner.company.com/jenkins/jnlpJars/slave.jar"
max_attempts=40 # ten minutes
echo "Waiting to try again. curl returneed $rc"
curl -fO "${slave_url}" >>slave.log
rc=$?
if [ $rc -ne 0 -a $max_attempts -gt 0 ]; then
echo "Waiting to try again. curl returneed $rc"
sleep 5
curl -fO "${slave_url}" >>slave.log
rc=$?
if [ $rc -eq 0 ]; then
zip -T slave.jar
rc=$?
fi
let max_attempts-=1
fi
# Simulator
java -jar slave.jar -jnlpUrl https://gardner.company.com/jenkins/computer/buildmachine/slave-agent.jnlp -secret YOUR_SECRET_KEY
The build user is set to automatically login. You can see the arguments to the slave.jar app by executing:
gardner:~ buildmachine$ java -jar slave.jar --help
"--help" is not a valid option
java -jar slave.jar [options...]
-auth user:pass : If your Jenkins is security-enabled, specify
a valid user name and password.
-connectTo HOST:PORT : make a TCP connection to the given host and
port, then start communication.
-cp (-classpath) PATH : add the given classpath elements to the
system classloader.
-jar-cache DIR : Cache directory that stores jar files sent
from the master
-jnlpCredentials USER:PASSWORD : HTTP BASIC AUTH header to pass in for making
HTTP requests.
-jnlpUrl URL : instead of talking to the master via
stdin/stdout, emulate a JNLP client by
making a TCP connection to the master.
Connection parameters are obtained by
parsing the JNLP file.
-noReconnect : Doesn't try to reconnect when a communication
fail, and exit instead
-proxyCredentials USER:PASSWORD : HTTP BASIC AUTH header to pass in for making
HTTP authenticated proxy requests.
-secret HEX_SECRET : Slave connection secret to use instead of
-jnlpCredentials.
-slaveLog FILE : create local slave error log
-tcp FILE : instead of talking to the master via
stdin/stdout, listens to a random local
port, write that port number to the given
file, then wait for the master to connect to
that port.
-text : encode communication with the master with
base64. Useful for running slave over 8-bit
unsafe protocol like telnet
gardner:~ buildmachine$
For a discussion about OSX slaves and how the master is launched please see this Jenkins bug: https://issues.jenkins-ci.org/browse/JENKINS-21237
Erik - I ended up doing the items documented here:
Essentially:
The first problem, is that you do have to have the user that runs the builds also logged in to the console on that Mac build machine. It needs to be able to pop up the simulator, and will fail if you don’t have a user logged in — as it can’t do this entirely headless without a display.
Secondly, the XCode Developer tools requires elevated privileges in order to execute all of the tasks on the Unit tests. Sometimes you may miss seeing it, but without these, the Simulator will give you an authentication prompt that never clears.
A first solution to this (on Mavericks) is to run:
sudo security authorizationdb write system.privilege.taskport allow
This will eliminate one class of these authentication popups. You’ll also need to run:
sudo DevToolsSecurity --enable
Per Apple’s man page on this tool:
On normal user systems, the first time in a given login session that
any such Apple-code-signed debugger or performance analysis tools are
used to examine one of the user’s processes, the user is queried for
an administator password for authorization. DevToolsSecurity tool to
change the authorization policies, such that a user who is a member of
either the admin group or the _developer group does not need to enter
an additional password to use the Apple-code-signed debugger or
performance analysis tools.
Only issue is that these same things seem to be broken once I upgraded to Xcode 6. Back to the drawing board....