I want to get the microservice subscribed tenant status value using cumulocity java sdk client. i am able to fetch the tenant status value("ACTIVE"/"SUSPENDED"/"DELETED") using the Rest api request GET url: {{baseurl}}/tenant/tenants/{tenantId}.
I didn't find any direct way to get the subscribed tenancy status using cumulocity java sdk or microservice sdk.
http://resources.cumulocity.com/documentation/javasdk/current/index.html http://resources.cumulocity.com/documentation/microservicesdk/current/
So currently i am trying to get the tenant status value using "com.cumulocity.sdk.client.RestConnector" to make the above http GET url call but i am getting the HTTP Error: 403 Forbidden and "Access is denied".
This is credentials/permission issue at microservice level..
import com.cumulocity.microservice.context.credentials.MicroserviceCredentials;
import com.cumulocity.microservice.subscription.service.MicroserviceSubscriptionsService;
import com.cumulocity.rest.representation.tenant.TenantRepresentation;
import com.cumulocity.model.authentication.CumulocityBasicCredentials;
....
@Value("#{systemEnvironment['C8Y_BASEURL']}")
private String baseUrl;
@Autowired
private MicroserviceSubscriptionsService subscriptionsService;
....
Iterator<MicroserviceCredentials> tenantCredentials = subscriptionsService.getAll().iterator();
while (tenantCredentials.hasNext()) {
MicroserviceCredentials tenantCredential = tenantCredentials.next();
subscriptionsService.runForTenant
(tenantCredential.getTenant(), ()-> {
String path = baseUrl+"/tenant/tenants/"+tenantCredential.getTenant();
Platform platform = new PlatformImpl(baseUrl, CumulocityBasicCredentials.builder()
.tenantId(tenantCredential.getTenant())
.username(tenantCredential.getUsername())
.password(tenantCredential.getPassword())
.build());
TenantRepresentation tenantReps = platform.rest().get(path, CumulocityMediaType.APPLICATION_JSON_TYPE, TenantRepresentation.class);
if (!isNullOrEmpty(tenantReps)) {
String tenantStatus = tenantReps.getStatus();
log.info("tenant status value : " + tenantStatus);
}
}
});
}
My java microserive has "MULTI_TENANT" isolation. cumulocity.json File:
....
"isolation": "MULTI_TENANT",
"requiredRoles": [
"ROLE_TENANT_MANAGEMENT_ADMIN",
"ROLE_TENANT_MANAGEMENT_READ",
"ROLE_TENANT_ADMIN"
..
],
....
How we can fetch the microservice subscribe tenant status value("ACTIVE"/"SUSPENDED"/"DELETED") using java sdk. Here, i am trying to fetch the TenantRepresentation.getStatus() value. Appreciate your help here.
I think the issue is, that you are not using the parent tenant credentials but the credentials of the tenant. The documentation states:
ROLE_TENANT_MANAGEMENT_READ AND the current tenant is its parent OR is the management tenant
So either you use /tenant/currentTenant with a tenant-user or you use /tenant/tenants/{tenantId} only with a parent-tenant user.