Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tenant activate and deactivate by tenant id #222

Merged
merged 1 commit into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 " +
dewniMW marked this conversation as resolved.
Show resolved Hide resolved
"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