Failed getting affiliation at the time of user registration using Fabric Client Java SDK V1.0.1

3.2k Views Asked by At

I have a Hyperledger Fabric V1.0 network setup using Build Your First Network.

I have made the network up by running the command ./byfn.sh -m up. Now all the Peers, Orderers and CAs(configured in docker-compose-e2e.yaml) are up and running.

This is my docker ps enter image description here

And I am trying to connect to this network using fabric-sdk-java.

But when doing user registration using the following code

HFCAClient ca = sampleOrg.getCAClient();
final String orgName = sampleOrg.getName();
final String mspid = sampleOrg.getMSPID();
ca.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());
SampleUser admin = sampleStore.getMember("ädmin", orgName);
if (!admin.isEnrolled()) {  //Preregistered admin only needs to be enrolled with Fabric caClient.
    admin.setEnrollment(ca.enroll(admin.getName(), "adminpw"));
    admin.setMspId(mspid);
}   

sampleOrg.setAdmin(admin); // The admin of this org --
SampleUser user = sampleStore.getMember("user", sampleOrg.getName());
if (!user.isRegistered()) {  // users need to be registered AND enrolled
    RegistrationRequest rr = new RegistrationRequest(user.getName(), "org1.department1");
    user.setEnrollmentSecret(ca.register(rr, admin// here comes the error
}

I am getting the error

2017-08-29 07:44:01,132 main ERROR HFCAClient:237 - com.test.blockchain.client.test.SampleUser@73846619
org.hyperledger.fabric_ca.sdk.exception.RegistrationException: Error while registering the user com.test.blockchain.client.test.SampleUser@73846619 url: https://192.168.99.100:7054  POST request to https://192.168.99.100:7054/api/v1/register failed request body {"id":"user1","type":"user","max_enrollments":0,"affiliation":"org1.department1","attrs":[]} with status code: 500. Response: {"success":false,"result":null,"errors":[{"code":0,"message":"Failed getting affiliation 'org1.department1': sql: no rows in result set"}],"messages":[]}
 
    at org.hyperledger.fabric_ca.sdk.HFCAClient.register(HFCAClient.java:236)
    at com.test.blockchain.client.test.Test.setup(Test.java:164)
    at com.test.blockchain.client.test.Test.main(Test.java:982)
Caused by: java.lang.Exception: POST request to https://192.168.99.100:7054/api/v1/register failed request body {"id":"user1","type":"user","max_enrollments":0,"affiliation":"org1.department1","attrs":[]} with status code: 500. Response: {"success":false,"result":null,"errors":[{"code":0,"message":"Failed getting affiliation 'org1.department1': sql: no rows in result set"}],"messages":[]}

    at org.hyperledger.fabric_ca.sdk.HFCAClient.httpPost(HFCAClient.java:609)
    at org.hyperledger.fabric_ca.sdk.HFCAClient.register(HFCAClient.java:227)
    ... 2 more

I am referring the codes shown in the unit test class End2endIT.java

Someone please share your knowledge to find out where I am doing wrong.

Also I am not sure where it is configuring "affiliation":"org1.department1".
Do I need to add anything in my .yaml file?

4

There are 4 best solutions below

4
On

You configure the affiliation when you create the crypto material. In your case when you generate the ./byfn.sh -m up command. You have created your keys (your certificates) when you executed the ./byfn.sh -m up, so you don't need to call the CA to register any user.

Also, your error code is the 500, so the cause of your error should be other. Could you try to invoke the chaincode?

Have you changed something in the crypto-config.yaml file? And in the docker-compose-e2e.yaml file?

2
On

These are the affiliation which are bootstrapped for the any CA containers

> affiliations:   
>   org1:
>       - department1
>       - department2    
>   org2:
>       - department1

But there function though which you can add New affiliation based on your organization

await caClient.newAffiliationService().create({ "name": "AFFILIATION_NAME }, adminObj)
1
On

In line:

SampleUser admin = sampleStore.getMember("ädmin", orgName);

you may have to replace the ä in "ädmin".

0
On

I'm not sure about the error you are getting for org1.department1. But even I had faced this similar issue while creating new org3. I was getting error Failed getting affiliation 'org3.department1': : scode: 404, code: 63, msg: Failed to get Affiliation: sql: no rows in result set.

To answer where the setting of the Affiliation happens. It is bootstrapped, which is defined the file /etc/hyperledger/fabric-ca-server/fabric-ca-client-config.yaml of CA Docker container

affiliations:
   org1:
      - department1
      - department2
   org2:
      - department1

Link to the file : http://hyperledger-fabric-ca.readthedocs.io/en/latest/serverconfig.html