Hi,

I am trying to programmatically create a DBCP Controller Service from a Java 
program and I am getting an error returned from 
POST/process-groups/{id}/controller-services.

Exception when calling: ControllerServicesApi#createControllerService
               Response body: Unable to create component to verify if it 
references any Controller Services. Contact the system administrator.
               io.swagger.client.ApiException: Unauthorized
                              at 
io.swagger.client.ApiClient.handleResponse(ApiClient.java:1058)
                              at 
io.swagger.client.ApiClient.execute(ApiClient.java:981)
                              at 
io.swagger.client.api.ProcessgroupsApi.createControllerServiceWithHttpInfo(ProcessgroupsApi.java:396)
                              at 
io.swagger.client.api.ProcessgroupsApi.createControllerService(ProcessgroupsApi.java:381)
                              at 
com.bdss.nifi.trickle.NiFiRestClient.createControllerService(NiFiRestClient.java:304)
                              at 
com.bdss.nifi.trickle.NiFiRestClient.createDbcp(NiFiRestClient.java:347)
                              at 
com.bdss.nifi.trickle.resources.NiFiResourceManager.getMdmDbcp(NiFiResourceManager.java:45)
                              at 
com.bdss.nifi.trickle.Trickle.createTemplateConfig(Trickle.java:57)
                              at 
com.bdss.nifi.trickle.Trickle.main(Trickle.java:212)

I don't have any security mechanisms enabled yet. I have no problems creating 
Database Connection Pooling Service Controller from NiFi gui and using it with 
ExecuteSQL processor. Below is my code which tries to generate DBCP Controller 
Service.
processgroupsApi.createControllerService(groupId, controllerServiceEntity) call 
in createControllerService method maps directly to 
POST/process-groups/{id}/controller-services and the rest of the logic should 
be straight-forward.  What am I missing in my code? Thanks very much!


public ControllerServiceEntity createControllerService(String groupId,
                                                                      
ControllerServiceEntity  controllerServiceEntity) {

                              try {
                              // processgroupsApi.createControllerService wraps 
POST/process-groups/{id}/controller-services
                                             controllerServiceEntity = 
processgroupsApi.createControllerService(groupId, controllerServiceEntity);
                              } catch (ApiException e) {
                                             
printException("ControllerServicesApi#createControllerService", e);
                              }
                              return controllerServiceEntity;
               }

               public ControllerServiceEntity createDbcp(String groupId,
                                                         String dbUrl,
                                                         String driverClass,
                                                         String driverDirectory,
                                                         String dbUser,
                                                         String pwd,
                                                         int    maxWaitTime,
                                                         int    
maxConnectionTotal,
                                                         String validationQuery 
) {

                              Map<String,String> props = new HashMap<>();

                              props.put("Database Connection URL", "dbUrl");
                              props.put("Database Driver Class Name", 
"driverClass");
                              props.put("Database Driver Location(s)", 
"driverDirectory");
                              props.put("Database User", "dbUser");
                              props.put("Password", "pwd");
                              props.put("Max Wait Time", "maxWaitTime");
                              props.put("Max Total Connections", 
"maxConnectionTotal");
                              props.put("Validation query", "validationQuery");

                              RevisionDTO revision = new RevisionDTO()
                                                            .clientId(clientId)
                                                            .version(0L);

                              ControllerServiceDTO component = new 
ControllerServiceDTO()
                                                            
.parentGroupId(groupId)
                                                            
.name("DBCPConnectionPool")
                                                            
.type("DBCPConnectionPool 1.6.0-SNAPSHOT")
                                                            
.state(ControllerServiceDTO.StateEnum.ENABLED)
                                                            .properties(props);

                              ControllerServiceEntity dbcp = new 
ControllerServiceEntity()
                                                            
.component(component)
                                                            .revision(revision);

                              dbcp = createControllerService(groupId, dbcp);

                              return dbcp;
               }



STATEMENT OF CONFIDENTIALITY The information contained in this email message 
and any attachments may be confidential and legally privileged and is intended 
for the use of the addressee(s) only. If you are not an intended recipient, 
please: (1) notify me immediately by replying to this message; (2) do not use, 
disseminate, distribute or reproduce any part of the message or any attachment; 
and (3) destroy all copies of this message and any attachments.

Reply via email to