Search in sources :

Example 81 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class UploadCSARSStepDefinition method I_should_have_last_update_date_greater_than_creation_date.

@Then("^I should have last update date greater than creation date$")
public void I_should_have_last_update_date_greater_than_creation_date() throws Throwable {
    NodeType idnt = JsonUtil.read(Context.getInstance().takeRestResponse(), NodeType.class).getData();
    Assert.assertTrue(idnt.getLastUpdateDate().after(idnt.getCreationDate()));
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Then(cucumber.api.java.en.Then)

Example 82 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class UploadCSARSStepDefinition method I_should_have_last_update_date_equals_to_creation_date.

@Then("^I should have last update date equals to creation date$")
public void I_should_have_last_update_date_equals_to_creation_date() throws Throwable {
    NodeType idnt = JsonUtil.read(Context.getInstance().takeRestResponse(), NodeType.class).getData();
    Assert.assertTrue(idnt.getLastUpdateDate().equals(idnt.getCreationDate()));
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Then(cucumber.api.java.en.Then)

Example 83 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class QuickSearchDefinitionsSteps method createAndIndexComponent.

private void createAndIndexComponent(int count, String type, int countHavingProperty, String property, String propertyValue) throws Exception {
    testDataList.clear();
    Class<?> clazz = QUERY_TYPES.get(type).getIndexedToscaElementClass();
    String typeName = MappingBuilder.indexTypeFromClass(clazz);
    int remaining = countHavingProperty;
    for (int i = 0; i < count; i++) {
        AbstractToscaType componentTemplate = (AbstractToscaType) clazz.newInstance();
        componentTemplate.setElementId(type + "_" + i);
        componentTemplate.setArchiveVersion(DEFAULT_ARCHIVE_VERSION);
        componentTemplate.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
        if (property != null && remaining > 0) {
            if (type.equalsIgnoreCase("node types")) {
                switch(property) {
                    case "elementId":
                        ((NodeType) componentTemplate).setElementId(propertyValue + "_" + remaining);
                        break;
                    default:
                        break;
                }
            } else if (type.equalsIgnoreCase("relationship types")) {
                ((RelationshipType) componentTemplate).setValidSources(new String[] { propertyValue });
            }
            remaining -= 1;
        }
        String serializeDatum = jsonMapper.writeValueAsString(componentTemplate);
        log.debug("Saving in ES: " + serializeDatum);
        esClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName).setSource(serializeDatum).setRefresh(true).execute().actionGet();
        if (componentTemplate instanceof NodeType) {
            testDataList.add((NodeType) (componentTemplate));
        }
    }
    indexedTypes.put(type, typeName);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 84 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class ServiceResourceService method update.

private void update(String resourceId, String name, String version, String description, String nodeTypeStr, String nodeTypeVersion, Map<String, AbstractPropertyValue> nodeProperties, Map<String, Capability> nodeCapabilities, Map<String, String> nodeAttributeValues, String[] locations, Map<String, String> capabilitiesRelationshipTypes, Map<String, String> requirementsRelationshipTypes, boolean patch) throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
    ServiceResource serviceResource = getOrFail(resourceId);
    failUpdateIfManaged(serviceResource, patch, name, version, nodeTypeStr, nodeTypeVersion, nodeProperties, nodeCapabilities, nodeAttributeValues);
    boolean ensureUniqueness = false;
    boolean isDeployed = !ToscaNodeLifecycleConstants.INITIAL.equals(serviceResource.getNodeInstance().getAttributeValues().get(ToscaNodeLifecycleConstants.ATT_STATE));
    String updatedState = nodeAttributeValues == null ? null : nodeAttributeValues.get(ToscaNodeLifecycleConstants.ATT_STATE);
    if (!patch || updatedState != null) {
        // in case of an update or when patching the state: check that the new state is a valid state
        if (!ToscaNodeLifecycleConstants.TOSCA_STATES.contains(updatedState)) {
            throw new IllegalArgumentException("State <" + updatedState + "> is not a valid state value must be one of " + ToscaNodeLifecycleConstants.TOSCA_STATES.toString());
        }
    }
    boolean isUpdateDeployed = updatedState == null ? isDeployed : !ToscaNodeLifecycleConstants.INITIAL.equals(nodeAttributeValues.get(ToscaNodeLifecycleConstants.ATT_STATE));
    NodeType nodeType = null;
    // Updating a running service is not yet authorized
    if (isDeployed && isUpdateDeployed) {
        // Patch operation is allowed only on the service description or locations authorized for matching.
        if (!patch || name != null || version != null || nodeTypeStr != null || nodeTypeVersion != null || nodeProperties != null || nodeCapabilities != null || nodeAttributeValues != null || capabilitiesRelationshipTypes != null || requirementsRelationshipTypes != null) {
            throw new UnsupportedOperationException("Update is not allowed on a running service, please use patch if you wish to change locations or authorizations.");
        }
    } else {
        ensureUniqueness = PatchUtil.set(serviceResource, "name", name, patch);
        ensureUniqueness = PatchUtil.set(serviceResource, "version", version, patch) || ensureUniqueness;
        // Node instance properties update
        nodeType = toscaTypeSearchService.findOrFail(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType(), serviceResource.getNodeInstance().getTypeVersion());
        // node instance type update
        PatchUtil.set(serviceResource.getNodeInstance().getNodeTemplate(), "type", nodeTypeStr, patch);
        PatchUtil.set(serviceResource.getNodeInstance(), "typeVersion", nodeTypeVersion, patch);
        // update half-relationship type
        serviceResource.setCapabilitiesRelationshipTypes(PatchUtil.setMap(serviceResource.getCapabilitiesRelationshipTypes(), capabilitiesRelationshipTypes, patch));
        serviceResource.setRequirementsRelationshipTypes(PatchUtil.setMap(serviceResource.getRequirementsRelationshipTypes(), requirementsRelationshipTypes, patch));
        // validate the half-relationship types exist
        validateRelationshipTypes(serviceResource, nodeType);
        // Node instance properties update
        nodeType = toscaTypeSearchService.findOrFail(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType(), serviceResource.getNodeInstance().getTypeVersion());
        if (patch) {
            nodeInstanceService.patch(nodeType, serviceResource.getNodeInstance(), nodeProperties, nodeCapabilities, nodeAttributeValues);
        } else {
            nodeInstanceService.update(nodeType, serviceResource.getNodeInstance(), nodeProperties, nodeCapabilities, nodeAttributeValues);
        }
    }
    // description, authorized locations and authorizations can be updated even when deployed.
    // Note that changing the locations or authorizations won't impact already deployed applications using the service
    PatchUtil.set(serviceResource, "description", description, patch);
    updateLocations(serviceResource, locations);
    if (isDeployed && !isUpdateDeployed) {
        // un-deploying a service is authorized only if the service is not used.
        failIdUsed(serviceResource.getId());
    }
    if (!isDeployed && isUpdateDeployed) {
        // check that all required properties are defined
        if (nodeType == null) {
            nodeType = toscaTypeSearchService.findOrFail(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType(), serviceResource.getNodeInstance().getTypeVersion());
        }
        nodeInstanceService.checkRequired(nodeType, serviceResource.getNodeInstance());
    }
    save(serviceResource, ensureUniqueness);
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) ServiceResource(alien4cloud.model.service.ServiceResource)

Example 85 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class ServiceResourceService method create.

/**
 * Create a service.
 *
 * @param serviceName The unique name that defines the service from user point of view.
 * @param serviceVersion The id of the plugin used to communicate with the orchestrator.
 * @param serviceNodeType The type of the node type used to create the service.
 * @param serviceNodeVersion The version of the node type used to create the service.
 * @param environmentId In case the service is created out of an alien environment the id of the environment, null if not.
 * @return The generated identifier for the service.
 */
public String create(String serviceName, String serviceVersion, String serviceNodeType, String serviceNodeVersion, String environmentId) {
    ServiceResource serviceResource = new ServiceResource();
    // generate an unique id
    serviceResource.setId(UUID.randomUUID().toString());
    serviceResource.setName(serviceName);
    serviceResource.setVersion(serviceVersion);
    serviceResource.setEnvironmentId(environmentId);
    // build a node instance from the given type
    NodeType nodeType = toscaTypeSearchService.findOrFail(NodeType.class, serviceNodeType, serviceNodeVersion);
    serviceResource.setNodeInstance(nodeInstanceService.create(nodeType, serviceNodeVersion));
    serviceResource.setDependency(new CSARDependency(nodeType.getArchiveName(), nodeType.getArchiveVersion()));
    // ensure uniqueness and save
    save(serviceResource, true);
    // TODO: send an event: a service has been created
    return serviceResource.getId();
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) ServiceResource(alien4cloud.model.service.ServiceResource) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7