Created on 07-08-2016 08:54 AM - edited 09-16-2022 03:29 AM
I'm trying to set a property using the CM Java API but it's throwing a null pointer exception in CM. Do I need to set additional properties? Here's what I have:
val clusterName = "cluster1"
val service: String = "OOZIE"
val apiServiceConfig = new ApiServiceConfig
val apiConfig = new ApiConfig("oozie_database_type", "mysql")
apiServiceConfig.add(apiConfig)
val apiService = new ApiService
apiService.setConfig(apiServiceConfig)
apiService.setType(service)
apiService.setName(service)
val clusterRef = new ApiClusterRef()
clusterRef.setClusterName(clusterName)
apiService.setClusterRef(clusterRef)
apiConnection.clustersResource
.getServicesResource(clusterName)
.updateService(service, apiService)
It's not giving me an error message on the client side, the clouder api debug logs on CM show this:
UT /api/v12/clusters/cluster1/services/OOZIE
Encoding: UTF-8
Authentication: admin [AUTH_AUDITS, AUTH_BDR_ADMIN, AUTH_DASHBOARDS, AUTH_DECOMMISSION_HOST, AUTH_DECOMMISSION_OTHER, AUTH_FULL_ADMIN_CONFIG, AUTH_KEY_ADMIN, AUTH_KMS_POWER_OPS, AUTH_MAINTENANCE_MODE, AUTH_NAVIGATOR, AUTH_POWER_OPS, AUTH_REDACTION, AUTH_SERVICE_CONFIG, AUTH_USERS_CONFIG, ROLE_ADMIN, ROLE_USER]
Headers:
Accept=[application/json]
Authorization=[Basic YWRtaW46YWRtaW4=]
Cache-Control=[no-cache]
connection=[keep-alive]
Content-Length=[205]
content-type=[application/json]
Host=[172.19.0.5:7180]
Pragma=[no-cache]
User-Agent=[Apache CXF 2.7.7]
Body:
{
"name" : "OOZIE",
"type" : "OOZIE",
"clusterRef" : {
"clusterName" : "cluster1"
},
"config" : {
"items" : [ {
"name" : "oozie_database_type",
"value" : "mysql"
} ]
}
}
2016-07-08 15:28:50,879 DEBUG 275074659@scm-web-15:com.cloudera.api.dao.impl.ManagerDaoBase: Skipping retry for method (last exception): public abstract com.cloudera.api.model.ApiService com.cloudera.api.dao.ServiceManagerDao.updateService(java.lang.String,java.lang.String,com.cloudera.api.model.ApiService); total attempts: 1, total time elapsed: 3, last exception: java.lang.NullPointerException
2016-07-08 15:28:50,880 WARN 275074659@scm-web-15:com.cloudera.api.ApiExceptionMapper: Unexpected exception.
java.lang.NullPointerException
2016-07-08 15:28:50,880 DEBUG 275074659@scm-web-15:com.cloudera.api.ApiInvoker: API Error 500 [/api/v12/clusters/cluster1/services/OOZIE]: ApiErrorMessage{null}
2016-07-08 15:28:50,880 DEBUG 275074659@scm-web-15:com.cloudera.api.ApiInvoker: API Error 500 [/api/v12/clusters/cluster1/services/OOZIE]: ApiErrorMessage{null}
2016-07-08 15:28:50,880 DEBUG 275074659@scm-web-15:com.cloudera.api.ApiInvoker: API Error 500 [/api/v12/clusters/cluster1/services/OOZIE]: ApiErrorMessage{null}
2016-07-08 15:28:50,880 DEBUG 275074659@scm-web-15:com.cloudera.api.ApiInvoker: API Error 500 [/api/v12/clusters/cluster1/services/OOZIE]: ApiErrorMessage{null}
2016-07-08 15:28:50,881 DEBUG 275074659@scm-web-15:com.cloudera.api.LoggingOutInterceptor: API response:
---------- id: 3090
Response code: 500
Content-Type: application/json
Headers:
Date=[Fri, 08 Jul 2016 15:28:50 GMT]
Body:
{ }
Created 07-08-2016 11:24 AM
This sample works, I needed to change the role config not the service config. I'm using autoAssignRoles so I didn't know the role names and need to query them. Since oozie only has one role I can just grab the first one that matches.
val clusterName = "cluster1"
val serviceName = "OOZIE"
val apiServiceConfig = new ApiServiceConfig
val apiConfig = new ApiConfig("oozie_database_type", "postgresql")
apiServiceConfig.add(apiConfig)
val rolesResource: RolesResourceV11 = apiConnection.clustersResource.getServicesResource(clusterName).getRolesResource(serviceName)
val roles: ApiRoleList = rolesResource.readRoles(DataView.FULL)
val oozieRole: String = roles.asScala.filter(x => x.getName.startsWith(serviceName)).head.getName
apiConnection.clustersResource
.getServicesResource(clusterName)
.getRolesResource(serviceName).updateRoleConfig(oozieRole, "use mysql db", apiServiceConfig)
Created 07-08-2016 11:24 AM
This sample works, I needed to change the role config not the service config. I'm using autoAssignRoles so I didn't know the role names and need to query them. Since oozie only has one role I can just grab the first one that matches.
val clusterName = "cluster1"
val serviceName = "OOZIE"
val apiServiceConfig = new ApiServiceConfig
val apiConfig = new ApiConfig("oozie_database_type", "postgresql")
apiServiceConfig.add(apiConfig)
val rolesResource: RolesResourceV11 = apiConnection.clustersResource.getServicesResource(clusterName).getRolesResource(serviceName)
val roles: ApiRoleList = rolesResource.readRoles(DataView.FULL)
val oozieRole: String = roles.asScala.filter(x => x.getName.startsWith(serviceName)).head.getName
apiConnection.clustersResource
.getServicesResource(clusterName)
.getRolesResource(serviceName).updateRoleConfig(oozieRole, "use mysql db", apiServiceConfig)