private void doScaleNode(final String nodeTemplateId, final int instances, final IPaaSCallback<Object> callback, final Deployment deployment,
final DeploymentTopology topology, NodeTemplate nodeTemplate, SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
final Capability capability = NodeTemplateUtils.getCapabilityByTypeOrFail(nodeTemplate, NormativeCapabilityTypes.SCALABLE);
final int previousInitialInstances = TopologyUtils.getScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, capability);
final int newInitialInstances = previousInitialInstances + instances;
log.info("Scaling [ {} ] node from [ {} ] to [ {} ]. Updating runtime topology...", nodeTemplateId, previousInitialInstances, newInitialInstances);
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, newInitialInstances, capability);
alienMonitorDao.save(topology);
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, topology, secretProviderConfigurationAndCredentials);
orchestratorPlugin.scale(deploymentContext, nodeTemplateId, instances, new IPaaSCallback() {
@Override
public void onFailure(Throwable throwable) {
log.info("Failed to scale [ {} ] node from [ {} ] to [ {} ]. rolling back to {}...", nodeTemplateId, previousInitialInstances,
newInitialInstances, previousInitialInstances);
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, previousInitialInstances, capability);
alienMonitorDao.save(topology);
callback.onFailure(throwable);
}
@Override
public void onSuccess(Object data) {
callback.onSuccess(data);
}
});
}
}