Search in sources :

Example 6 with InstanceInformation

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);
    }
}
Also used : InstanceInformation(alien4cloud.paas.model.InstanceInformation) Map(java.util.Map)

Example 7 with InstanceInformation

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));
}
Also used : Set(java.util.Set) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) ManagedServiceUpdatedEvent(org.alien4cloud.alm.events.ManagedServiceUpdatedEvent) InstanceInformation(alien4cloud.paas.model.InstanceInformation) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) Map(java.util.Map)

Example 8 with InstanceInformation

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);
}
Also used : ScalingPolicy(org.alien4cloud.tosca.model.templates.ScalingPolicy) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Topology(org.alien4cloud.tosca.model.templates.Topology) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Map(java.util.Map)

Example 9 with InstanceInformation

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());
    }
}
Also used : InstanceInformation(alien4cloud.paas.model.InstanceInformation) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map)

Example 10 with InstanceInformation

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;
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

InstanceInformation (alien4cloud.paas.model.InstanceInformation)12 Map (java.util.Map)11 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)5 Topology (org.alien4cloud.tosca.model.templates.Topology)4 Deployment (alien4cloud.model.deployment.Deployment)2 MaintenanceModeException (alien4cloud.paas.exception.MaintenanceModeException)2 PaaSInstancePersistentResourceMonitorEvent (alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 Application (alien4cloud.model.application.Application)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)1 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)1 PaaSInstanceStateMonitorEvent (alien4cloud.paas.model.PaaSInstanceStateMonitorEvent)1 PaaSMessageMonitorEvent (alien4cloud.paas.model.PaaSMessageMonitorEvent)1 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)1 RestResponse (alien4cloud.rest.model.RestResponse)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1