use of alien4cloud.paas.model.InstanceInformation in project alien4cloud by alien4cloud.
the class MockPaaSProvider method switchInstanceMaintenanceMode.
@Override
public void switchInstanceMaintenanceMode(PaaSDeploymentContext deploymentContext, String nodeTemplateId, String instanceId, boolean maintenanceModeOn) {
log.info(String.format("switchInstanceMaintenanceMode order received for node <%s>, instance <%s>, mode <%s>", nodeTemplateId, instanceId, maintenanceModeOn));
MockRuntimeDeploymentInfo runtimeDeploymentInfo = runtimeDeploymentInfos.get(deploymentContext.getDeploymentPaaSId());
if (runtimeDeploymentInfo == null) {
return;
}
final Map<String, Map<String, InstanceInformation>> existingInformations = runtimeDeploymentInfo.getInstanceInformations();
if (existingInformations != null && existingInformations.containsKey(nodeTemplateId) && existingInformations.get(nodeTemplateId).containsKey(instanceId)) {
InstanceInformation instanceInformation = existingInformations.get(nodeTemplateId).get(instanceId);
switchInstanceMaintenanceMode(deploymentContext.getDeploymentPaaSId(), nodeTemplateId, instanceId, instanceInformation, maintenanceModeOn);
}
}
use of alien4cloud.paas.model.InstanceInformation in project alien4cloud by alien4cloud.
the class ManagedServiceResourceEventService method updateRunningService.
private void updateRunningService(DeploymentTopology topology, Deployment deployment, ServiceResource serviceResource, String serviceState, Map<String, Map<String, InstanceInformation>> instanceInformation) {
// update the state
serviceResource.setState(serviceState);
// update deploymentId, in case it is not yet (when creating the service from an already started deployment)
serviceResource.setDeploymentId(deployment.getId());
// ensure the service is available on all of the deployment locations
updateLocations(serviceResource, deployment.getLocationIds());
// Map input properties from the topology as properties of the service instance
if (serviceResource.getNodeInstance().getNodeTemplate().getProperties() == null) {
serviceResource.getNodeInstance().getNodeTemplate().setProperties(Maps.newHashMap());
}
serviceResource.getNodeInstance().getNodeTemplate().getProperties().putAll(safe(topology.getAllInputProperties()));
// Map attributes from the instances to the actual service resource node.
for (Entry<String, Set<String>> nodeOutputAttrEntry : safe(topology.getOutputAttributes()).entrySet()) {
Map<String, InstanceInformation> instances = instanceInformation.get(nodeOutputAttrEntry.getKey());
if (instances == null) {
log.error("Failed to map attributes from node [ {} ] for service <id: {}, name: {}>. The node cannot be found in deployed topology [ {} ].", nodeOutputAttrEntry.getKey(), serviceResource.getId(), serviceResource.getName(), topology.getId());
} else if (instances.size() > 1) {
log.error("Services substitution does not yet supports the exposure of multiple instances");
} else {
InstanceInformation instance = instances.values().iterator().next();
// let's map attribute
for (String mappedAttribute : nodeOutputAttrEntry.getValue()) {
serviceResource.getNodeInstance().setAttribute(mappedAttribute, instance.getAttributes().get(mappedAttribute));
}
}
}
// Map output properties as attributes of the service instance
for (Entry<String, Set<String>> nodeOutputPropEntry : safe(topology.getOutputProperties()).entrySet()) {
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeOutputPropEntry.getKey());
for (String prop : nodeOutputPropEntry.getValue()) {
serviceResource.getNodeInstance().setAttribute(prop, PropertyUtil.serializePropertyValue(nodeTemplate.getProperties().get(prop)));
}
}
// Map capabilities output properties as attributes of the service instance (that are exposed as node properties)
for (Entry<String, Map<String, Set<String>>> nodeOutputCapaPropEntry : safe(topology.getOutputCapabilityProperties()).entrySet()) {
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeOutputCapaPropEntry.getKey());
for (Entry<String, Set<String>> outputCapaPropEntry : nodeOutputCapaPropEntry.getValue().entrySet()) {
Capability capability = nodeTemplate.getCapabilities().get(outputCapaPropEntry.getKey());
for (String prop : outputCapaPropEntry.getValue()) {
serviceResource.getNodeInstance().setAttribute(prop, PropertyUtil.serializePropertyValue(capability.getProperties().get(prop)));
}
}
}
serviceResource.getNodeInstance().getNodeTemplate().setCapabilities(Maps.newLinkedHashMap());
// Map capabilities exposed as is for the service node.
for (Entry<String, SubstitutionTarget> capabilityMapping : safe(topology.getSubstitutionMapping().getCapabilities()).entrySet()) {
Capability deployedCapability = topology.getNodeTemplates().get(capabilityMapping.getValue().getNodeTemplateName()).getCapabilities().get(capabilityMapping.getValue().getTargetId());
serviceResource.getNodeInstance().getNodeTemplate().getCapabilities().put(capabilityMapping.getKey(), deployedCapability);
// TODO improve while capabilities attributes will be really supported
// Workaround to support capabilities attributes is to use node attributes with keys in format capabilities.capaName.attributeName
mapCapabilityRequirementAttributes(serviceResource, instanceInformation, capabilityMapping.getValue().getNodeTemplateName(), "capabilities", capabilityMapping.getValue().getTargetId());
}
serviceResource.getNodeInstance().getNodeTemplate().setRequirements(Maps.newLinkedHashMap());
// Map requirements exposed as is for the service node.
for (Entry<String, SubstitutionTarget> requirementMapping : safe(topology.getSubstitutionMapping().getRequirements()).entrySet()) {
serviceResource.getNodeInstance().getNodeTemplate().getRequirements().put(requirementMapping.getKey(), topology.getNodeTemplates().get(requirementMapping.getValue().getNodeTemplateName()).getRequirements().get(requirementMapping.getValue().getTargetId()));
// TODO improve while requirements attributes will be really supported
// Workaround to support requirements attributes is to use node attributes with keys in format capabilities.capaName.attributeName
mapCapabilityRequirementAttributes(serviceResource, instanceInformation, requirementMapping.getValue().getNodeTemplateName(), "requirements", requirementMapping.getValue().getTargetId());
}
serviceResourceService.save(serviceResource);
// trigger a ManagedServiceUpdateEvent
publisher.publishEvent(new ManagedServiceUpdatedEvent(this, serviceResource, topology));
}
use of alien4cloud.paas.model.InstanceInformation in project alien4cloud by alien4cloud.
the class MockPaaSProvider method doDeploy.
@Override
protected synchronized void doDeploy(final PaaSTopologyDeploymentContext deploymentContext) {
log.info("Deploying deployment [" + deploymentContext.getDeploymentPaaSId() + "]");
paaSDeploymentIdToAlienDeploymentIdMap.put(deploymentContext.getDeploymentPaaSId(), deploymentContext.getDeploymentId());
Topology topology = deploymentContext.getDeploymentTopology();
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
if (nodeTemplates == null) {
nodeTemplates = Maps.newHashMap();
}
Map<String, Map<String, InstanceInformation>> currentInformations = Maps.newHashMap();
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) {
Map<String, InstanceInformation> instanceInformations = Maps.newHashMap();
currentInformations.put(nodeTemplateEntry.getKey(), instanceInformations);
ScalingPolicy policy = getScalingPolicy(nodeTemplateEntry.getKey(), nodeTemplates, topology);
int initialInstances = policy != null ? policy.getInitialInstances() : 1;
for (int i = 1; i <= initialInstances; i++) {
InstanceInformation newInstanceInformation = newInstance(i);
instanceInformations.put(String.valueOf(i), newInstanceInformation);
notifyInstanceStateChanged(deploymentContext.getDeploymentPaaSId(), nodeTemplateEntry.getKey(), String.valueOf(i), newInstanceInformation, 1);
}
}
runtimeDeploymentInfos.put(deploymentContext.getDeploymentPaaSId(), new MockRuntimeDeploymentInfo(deploymentContext, DeploymentStatus.DEPLOYMENT_IN_PROGRESS, currentInformations));
changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.DEPLOYMENT_IN_PROGRESS);
executorService.schedule(new Runnable() {
@Override
public void run() {
switch(deploymentContext.getDeployment().getSourceName()) {
case BAD_APPLICATION_THAT_NEVER_WORKS:
changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.FAILURE);
break;
case WARN_APPLICATION_THAT_NEVER_WORKS:
changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.WARNING);
break;
default:
changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.DEPLOYED);
}
}
}, 5, TimeUnit.SECONDS);
}
use of alien4cloud.paas.model.InstanceInformation in project alien4cloud by alien4cloud.
the class MockPaaSProvider method scale.
@Override
public void scale(PaaSDeploymentContext deploymentContext, String nodeTemplateId, final int instances, IPaaSCallback<?> callback) {
MockRuntimeDeploymentInfo runtimeDeploymentInfo = runtimeDeploymentInfos.get(deploymentContext.getDeploymentPaaSId());
if (runtimeDeploymentInfo == null) {
return;
}
Topology topology = runtimeDeploymentInfo.getDeploymentContext().getDeploymentTopology();
final Map<String, Map<String, InstanceInformation>> existingInformations = runtimeDeploymentInfo.getInstanceInformations();
if (existingInformations != null && existingInformations.containsKey(nodeTemplateId)) {
ScalingVisitor scalingVisitor = new ScalingVisitor() {
@Override
public void visit(String nodeTemplateId) {
Map<String, InstanceInformation> nodeInformations = existingInformations.get(nodeTemplateId);
if (nodeInformations != null) {
int currentSize = nodeInformations.size();
if (instances > 0) {
for (int i = currentSize + 1; i < currentSize + instances + 1; i++) {
nodeInformations.put(String.valueOf(i), newInstance(i));
}
} else {
for (int i = currentSize + instances + 1; i < currentSize + 1; i++) {
if (nodeInformations.containsKey(String.valueOf(i))) {
nodeInformations.get(String.valueOf(i)).setState("stopping");
nodeInformations.get(String.valueOf(i)).setInstanceStatus(InstanceStatus.PROCESSING);
}
}
}
}
}
};
doScaledUpNode(scalingVisitor, nodeTemplateId, topology.getNodeTemplates());
}
}
use of alien4cloud.paas.model.InstanceInformation in project yorc-a4c-plugin by ystia.
the class DeployTask method setupInstanceInformations.
private Map<String, Map<String, InstanceInformation>> setupInstanceInformations(Topology topology) {
log.debug("setupInstanceInformations for " + topology.getArchiveName() + " : " + topology.getArchiveVersion());
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
if (nodeTemplates == null) {
nodeTemplates = Maps.newHashMap();
}
Map<String, Map<String, InstanceInformation>> currentInformations = Maps.newHashMap();
for (Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) {
Map<String, InstanceInformation> instanceInformations = Maps.newHashMap();
currentInformations.put(nodeTemplateEntry.getKey(), instanceInformations);
int initialInstances = 1;
for (int i = 0; i < initialInstances; i++) {
InstanceInformation newInstanceInformation = orchestrator.newInstance(i);
instanceInformations.put(String.valueOf(i), newInstanceInformation);
}
}
return currentInformations;
}
Aggregations