Skip to content

Commit

Permalink
Add tenant activate and deactivate by tenant id
Browse files Browse the repository at this point in the history
  • Loading branch information
dewniMW committed May 13, 2022
1 parent 45685a1 commit 5e81229
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,32 @@ public void activateTenant(String tenantUniqueID) throws TenantMgtException {
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername() + "'");
}

@Override
public void activateTenant(int tenantId) throws TenantMgtException {

TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
String tenantDomain = null;
try {
Tenant tenant = (Tenant) tenantManager.getTenant(tenantId);
if (tenant == null) {
throw new TenantManagementClientException(ERROR_CODE_RESOURCE_NOT_FOUND.getCode(),
String.format(ERROR_CODE_RESOURCE_NOT_FOUND.getMessage(), tenantId));
}
tenantManager.activateTenant(tenantId);
tenantDomain = tenant.getDomain();
// Notify tenant activation to all listeners.
TenantMgtUtil.triggerTenantActivation(tenantId);
log.info(String.format("Tenant with id: %s and domain: %s activated by %s", tenantId,
tenantDomain, PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()));
} catch (org.wso2.carbon.user.api.UserStoreException e) {
throw new TenantManagementServerException(String.format("Error while retrieving or deactivating the " +
"tenant with id: %s", tenantId), e);
} catch (StratosException e) {
throw new TenantManagementServerException(String.format("Error in notifying tenant activation of tenant " +
"with id: %s and domain: %s", tenantId, tenantDomain), e);
}
}

public void deactivateTenant(String tenantUniqueID) throws TenantMgtException {

TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
Expand Down Expand Up @@ -239,6 +265,33 @@ public void deactivateTenant(String tenantUniqueID) throws TenantMgtException {
}
}

@Override
public void deactivateTenant(int tenantId) throws TenantMgtException {

TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
String tenantDomain = null;
try {
Tenant tenant = (Tenant) tenantManager.getTenant(tenantId);
if (tenant == null) {
throw new TenantManagementClientException(ERROR_CODE_RESOURCE_NOT_FOUND.getCode(),
String.format(ERROR_CODE_RESOURCE_NOT_FOUND.getMessage(), tenantId));
}
tenantDomain = tenant.getDomain();
// Notify tenant deactivation to all listeners.
TenantMgtUtil.triggerTenantDeactivation(tenantId);
tenantManager.deactivateTenant(tenantId);
TenantMgtUtil.unloadTenantConfigurations(tenantDomain, tenantId);
log.info(String.format("Tenant with id: %s and domain: %s deactivated by %s", tenantId,
tenantDomain, PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()));
} catch (org.wso2.carbon.user.api.UserStoreException e) {
throw new TenantManagementServerException(String.format("Error while retrieving or deactivating the " +
"tenant with id: %s", tenantId), e);
} catch (StratosException e) {
throw new TenantManagementServerException(String.format("Error while triggering tenant deactivation for " +
"the tenant with id: %s and domain: %s", tenantId, tenantDomain), e);
}
}

@Override
public void deleteTenantMetaData(String tenantUniqueIdentifier) throws TenantMgtException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,33 @@ TenantSearchResult listTenants(Integer limit, Integer offset, String sortOrder,
void activateTenant(String tenantUniqueIdentifier) throws TenantMgtException;

/**
* Deactivate the given tenant.
* Activate the given tenant by the tenant id.
*
* @param tenantId tenant id.
* @throws TenantMgtException if tenant activation fails.
*/
default void activateTenant(int tenantId) throws TenantMgtException {

}

/**
* Deactivate the given tenant by the tenant uuid.
*
* @param tenantUniqueIdentifier tenant uuid.
* @throws TenantMgtException if tenant deactivation fails.
*/
void deactivateTenant(String tenantUniqueIdentifier) throws TenantMgtException;

/**
* Deactivate the given tenant by the tenant id.
*
* @param tenantId tenant id.
* @throws TenantMgtException if tenant deactivation fails.
*/
default void deactivateTenant(int tenantId) throws TenantMgtException {

}

/**
* Delete tenant metadata.
*
Expand Down

0 comments on commit 5e81229

Please sign in to comment.