Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Closed
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 @@ -69,11 +69,10 @@
import org.wso2.carbon.registry.api.RegistryException;

import java.rmi.RemoteException;
import java.text.MessageFormat;
import java.util.*;

/**
* Auto Scaler Service API is responsible getting Partitions and Policies.
* Autoscaler Service API is responsible getting Partitions and Policies.
*/
public class AutoscalerServiceImpl implements AutoscalerService {

Expand Down Expand Up @@ -169,18 +168,19 @@ public boolean updateApplication(ApplicationContext applicationContext)
}

if (AutoscalerContext.getInstance().getApplicationContext(applicationId) == null) {
String msg = "Application is not found as ApplicationContext. Please add application before updating it";
String msg = "Application is not found as ApplicationContext. Please add application before updating it: " +
"[application-id] " + applicationId;
log.error(msg);
throw new ApplicationDefinitionException(msg);
}

if (ApplicationHolder.getApplications().getApplication(applicationId) == null) {
String msg = "Application is not found as Application. Please add application before updating it";
String msg = "Application is not found as Application. Please add application before updating it: " +
"[application-id] " + applicationId;
log.error(msg);
throw new ApplicationDefinitionException(msg);
}


ApplicationParser applicationParser = new DefaultApplicationParser();
Application application = applicationParser.parse(applicationContext);

Expand Down Expand Up @@ -270,7 +270,7 @@ public boolean deployApplication(String applicationId, String applicationPolicyI
applicationContext.setStatus(ApplicationContext.STATUS_DEPLOYED);
AutoscalerContext.getInstance().updateApplicationContext(applicationContext);

log.info("Waiting for application clusters to be created: [application] " + applicationId);
log.info("Waiting for application clusters to be created: [application-id] " + applicationId);
return true;
} catch (Exception e) {
ApplicationContext applicationContext = RegistryManager.getInstance().
Expand All @@ -280,7 +280,7 @@ public boolean deployApplication(String applicationId, String applicationPolicyI
applicationContext.setStatus(ApplicationContext.STATUS_CREATED);
AutoscalerContext.getInstance().updateApplicationContext(applicationContext);
}
String message = "Application deployment failed";
String message = "Application deployment failed: [application-id] " + applicationId;
log.error(message, e);
throw new RuntimeException(message, e);
}
Expand Down Expand Up @@ -354,7 +354,7 @@ private void addApplicationSignUp(ApplicationContext applicationContext, String
}
}
} catch (Exception e) {
String message = "Could not add application signup";
String message = "Could not add application signup: [application-id] " + applicationContext.getApplicationId();
log.error(message, e);
throw new RuntimeException(message, e);
}
Expand Down Expand Up @@ -402,7 +402,7 @@ private void removeApplicationSignUp(ApplicationContext applicationContext) {
}

} catch (Exception e) {
String message = "Could not remove application signup(s)";
String message = "Could not remove application signup(s): [application-id] " + applicationContext.getApplicationId();
log.error(message, e);
throw new RuntimeException(message, e);
}
Expand All @@ -418,7 +418,7 @@ private void encryptRepositoryPasswords(ApplicationSignUp applicationSignUp, Str
if (applicationSignUp.getArtifactRepositories() != null) {
for (ArtifactRepository artifactRepository : applicationSignUp.getArtifactRepositories()) {
String repoPassword = artifactRepository.getRepoPassword();
if ((artifactRepository != null) && (StringUtils.isNotBlank(repoPassword))) {
if ((StringUtils.isNotBlank(repoPassword))) {
String encryptedRepoPassword = CommonUtil.encryptPassword(repoPassword,
applicationKey);
artifactRepository.setRepoPassword(encryptedRepoPassword);
Expand Down Expand Up @@ -467,7 +467,7 @@ public boolean undeployApplication(String applicationId, boolean force) {
return false;
}
if (!force) {
// Gracefull undeployment flow
// Graceful undeployment flow
if (appMonitor.isTerminating()) {
log.info("Application monitor is already in terminating, graceful undeployment is has already been attempted thus not invoking again");
return false;
Expand All @@ -476,14 +476,16 @@ public boolean undeployApplication(String applicationId, boolean force) {
undeployApplicationGracefully(applicationId);
}
} else {
// force undeployment flow
// Forceful undeployment flow
if (appMonitor.isTerminating()) {

if (appMonitor.isForce()) {
log.warn("Force undeployment is already in progress, hence not invoking again");
log.warn(String.format("Force undeployment is already in progress, hence not invoking again: " +
"[application-id] %s", applicationId));
return false;
} else {
log.info(String.format("Previous gracefull undeployment is in progress for [application-id] %s , thus terminating instances directly", applicationId));
log.info(String.format("Previous graceful undeployment is in progress for [application-id] %s , " +
"thus terminating instances directly", applicationId));
appMonitor.setForce(true);
terminateAllApplicationMembersForcefully(applicationId);
}
Expand Down Expand Up @@ -570,15 +572,15 @@ public boolean deleteApplication(String applicationId) {

public boolean updateClusterMonitor(String clusterId, Properties properties) throws InvalidArgumentException {
if (log.isDebugEnabled()) {
log.debug(String.format("Updating Cluster monitor [Cluster id] %s ", clusterId));
log.debug(String.format("Updating Cluster monitor [cluster-id] %s", clusterId));
}
AutoscalerContext asCtx = AutoscalerContext.getInstance();
ClusterMonitor monitor = asCtx.getClusterMonitor(clusterId);

if (monitor != null) {
monitor.handleDynamicUpdates(properties);
} else {
log.debug(String.format("Updating Cluster monitor failed: Cluster monitor [Cluster id] %s not found.",
log.debug(String.format("Updating Cluster monitor failed: Cluster monitor [cluster-id] %s not found.",
clusterId));
}
return true;
Expand All @@ -587,7 +589,7 @@ public boolean updateClusterMonitor(String clusterId, Properties properties) thr
public boolean addServiceGroup(ServiceGroup servicegroup) throws InvalidServiceGroupException {

if (servicegroup == null || StringUtils.isEmpty(servicegroup.getName())) {
String msg = "Cartridge group can not be null service name can not be empty.";
String msg = "Cartridge group cannot be null or cartridge name cannot be empty.";
log.error(msg);
throw new IllegalArgumentException(msg);
}
Expand All @@ -598,11 +600,11 @@ public boolean addServiceGroup(ServiceGroup servicegroup) throws InvalidServiceG

String groupName = servicegroup.getName();
if (RegistryManager.getInstance().serviceGroupExist(groupName)) {
throw new InvalidServiceGroupException("Cartridge group with the name " + groupName + " already exists.");
throw new InvalidServiceGroupException(String.format("Cartridge group already exist: [group-name] %s", groupName));
}

if (log.isDebugEnabled()) {
log.debug(MessageFormat.format("Adding cartridge group {0}", servicegroup.getName()));
log.debug(String.format("Adding cartridge group: [group-name] %s", servicegroup.getName()));
}

String[] subGroups = servicegroup.getCartridges();
Expand Down Expand Up @@ -773,7 +775,7 @@ public boolean updateApplicationPolicy(ApplicationPolicy applicationPolicy)
String applicationPolicyId = applicationPolicy.getId();
ApplicationPolicy existingApplicationPolicy = PolicyManager.getInstance().getApplicationPolicy(applicationPolicyId);
if (existingApplicationPolicy == null) {
String msg = String.format("No such application poliicy found [application-policy-id] %s", applicationPolicyId);
String msg = String.format("No such application policy found [application-policy-id] %s", applicationPolicyId);
log.error(msg);
throw new ApplicatioinPolicyNotExistsException(msg);
}
Expand All @@ -793,15 +795,16 @@ public ApplicationPolicy[] getApplicationPolicies() {

private void terminateAllApplicationMembersForcefully(String applicationId) {
if (StringUtils.isEmpty(applicationId)) {
throw new IllegalArgumentException("Application Id can not be empty");
throw new IllegalArgumentException("Application Id cannot be empty");
}

Application application;
try {
ApplicationManager.acquireReadLockForApplication(applicationId);
application = ApplicationManager.getApplications().getApplication(applicationId);
if (application == null) {
log.warn(String.format("Could not find application, thus no members to be terminated [application-id] %s", applicationId));
log.warn(String.format("Could not find application, thus no members to be terminated [application-id] %s",
applicationId));
return;
}
} finally {
Expand All @@ -810,7 +813,6 @@ private void terminateAllApplicationMembersForcefully(String applicationId) {


Set<ClusterDataHolder> allClusters = application.getClusterDataRecursively();
//CloudControllerServiceClient cloudControllerServiceClient = CloudControllerServiceClient.getInstance().ter
for (ClusterDataHolder clusterDataHolder : allClusters) {
String serviceType = clusterDataHolder.getServiceType();
String clusterId = clusterDataHolder.getClusterId();
Expand All @@ -830,10 +832,12 @@ private void terminateAllApplicationMembersForcefully(String applicationId) {

for (String memberIdToTerminate : memberListToTerminate) {
try {
log.info(String.format("Terminating member forcefully [member-id] %s of the cluster [cluster-id] %s [application-id] %s", memberIdToTerminate, clusterId, application));
log.info(String.format("Terminating member forcefully [member-id] %s of the cluster [cluster-id] %s " +
"[application-id] %s", memberIdToTerminate, clusterId, application));
CloudControllerServiceClient.getInstance().terminateInstanceForcefully(memberIdToTerminate);
} catch (Exception e) {
log.error(String.format("Forcefull termination of member %s is failed, but continuing forcefull deletion of other members", memberIdToTerminate));
log.error(String.format("Forceful termination of member %s is failed, but continuing forceful " +
"deletion of other members", memberIdToTerminate));
}
}
}
Expand All @@ -853,9 +857,9 @@ public boolean addDeployementPolicy(DeploymentPolicy deploymentPolicy) throws Re
log.debug("Deployment policy definition: " + deploymentPolicy.toString());
}

String deploymentPolicyID = deploymentPolicy.getDeploymentPolicyID();
if (PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyID) != null) {
String message = "Deployment policy already exists: [deployment-policy-id] " + deploymentPolicyID;
String deploymentPolicyId = deploymentPolicy.getDeploymentPolicyID();
if (PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyId) != null) {
String message = "Deployment policy already exists: [deployment-policy-id] " + deploymentPolicyId;
log.error(message);
throw new DeploymentPolicyAlreadyExistsException(message);
}
Expand All @@ -865,7 +869,7 @@ public boolean addDeployementPolicy(DeploymentPolicy deploymentPolicy) throws Re
// PolicyManager.getInstance().persist();

if (log.isInfoEnabled()) {
log.info("Successfully added deployment policy: [deployment-policy-id] " + deploymentPolicyID);
log.info("Successfully added deployment policy: [deployment-policy-id] " + deploymentPolicyId);
}
return true;
}
Expand Down