public void unsubscribeFromCartridge (String tenantDomain, String alias)
throws ADCException, NotSubscribedException {
DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager = new DataInsertionAndRetrievalManager();
CartridgeSubscription cartridgeSubscription = dataInsertionAndRetrievalManager.getCartridgeSubscription(CarbonContext.getThreadLocalCarbonContext().getTenantId(), alias);
if(cartridgeSubscription != null) {
cartridgeSubscription.removeSubscription();
// Remove the information from Topology Model
// Not needed now. TopologyModel is now changed so that information is taken from subscriptions
//TopologyClusterInformationModel.getInstance().removeCluster(cartridgeSubscription.getSubscriber().getTenantId(),
// cartridgeSubscription.getType(), cartridgeSubscription.getAlias());
// remove subscription
try {
dataInsertionAndRetrievalManager.removeSubscription(cartridgeSubscription.getSubscriber().getTenantId(), alias);
} catch (PersistenceManagerException e) {
String errorMsg = "Error removing subscription for tenant " + tenantDomain + ", alias " + cartridgeSubscription.getAlias();
log.error(errorMsg);
throw new ADCException(errorMsg, e);
}
// Publish tenant un-subscribed event to message broker
CartridgeSubscriptionUtils.publishTenantUnSubscribedEvent(cartridgeSubscription.getSubscriber().getTenantId(),
cartridgeSubscription.getCartridgeInfo().getType());
// publishing to the unsubscribed event details to bam
CartridgeSubscriptionDataPublisher.publish(cartridgeSubscription
.getSubscriber().getTenantId(), cartridgeSubscription
.getSubscriber().getAdminUserName(), cartridgeSubscription
.getAlias(), cartridgeSubscription.getType(),
"",
cartridgeSubscription.getCartridgeInfo().getMultiTenant(),
cartridgeSubscription.getAutoscalingPolicyName(),
cartridgeSubscription.getDeploymentPolicyName(),
cartridgeSubscription.getCluster().getClusterDomain(),
cartridgeSubscription.getHostName(), cartridgeSubscription
.getMappedDomain(), "unsubscribed");
}
else {
String errorMsg = "No cartridge subscription found with [alias] " + alias + " for [tenant] " + tenantDomain;
log.error(errorMsg);