Search in sources :

Example 1 with MetaPropConfiguration

use of alien4cloud.model.common.MetaPropConfiguration in project alien4cloud by alien4cloud.

the class LocationService method createLocation.

private void createLocation(Orchestrator orchestrator, Location location, String infrastructureType) {
    ensureNameUnicityAndSave(location);
    // TODO checks that the infrastructure type is valid
    location.setInfrastructureType(infrastructureType);
    // TODO add User and Group managed by the Orchestrator security
    Set<CSARDependency> dependencies = locationArchiveIndexer.indexLocationArchives(orchestrator, location);
    location.setDependencies(dependencies);
    // initialize meta properties
    location.setMetaProperties(Maps.<String, String>newHashMap());
    // add existing meta properties to the cloud
    GetMultipleDataResult<MetaPropConfiguration> result = alienDAO.find(MetaPropConfiguration.class, singleKeyFilter("target", MetaPropertyTarget.LOCATION), Integer.MAX_VALUE);
    for (MetaPropConfiguration element : result.getData()) {
        if (Objects.equals(element.getTarget(), MetaPropertyTarget.LOCATION)) {
            // we only support string values for meta properties
            PropertyUtil.setScalarDefaultValueOrNull(location.getMetaProperties(), element.getId(), element.getDefault());
            log.debug("Added meta property [ {} ] to the new location [ {} ] ", element.getName(), location.getName());
        }
    }
    // save the new location
    alienDAO.save(location);
    try {
        autoConfigure(orchestrator, location);
    } catch (UnsupportedOperationException e) {
    // do nothing
    }
    // We call the LocationRessourceService to check the dependencies
    try {
        locationResourceService.getLocationResourcesFromOrchestrator(location);
    } catch (NotFoundException e) {
        // WARN: FIXME we load orch twice !!!!!!!!!!!!!!!!!!!!!!!!!
        delete(orchestrator.getId(), location.getId());
        throw new MissingCSARDependenciesException(e.getMessage());
    }
}
Also used : MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration) NotFoundException(alien4cloud.exception.NotFoundException) MissingCSARDependenciesException(alien4cloud.exception.MissingCSARDependenciesException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 2 with MetaPropConfiguration

use of alien4cloud.model.common.MetaPropConfiguration in project alien4cloud by alien4cloud.

the class MetaPropertiesService method getByIds.

/**
 * Load a map of MetaPropConfiguration from given ids.
 *
 * @param ids The ids to fetch
 * @return The a map id -> MetaPropConfiguration
 */
public Map<String, MetaPropConfiguration> getByIds(String[] ids) {
    Map<String, MetaPropConfiguration> configurationMap = Maps.newHashMap();
    List<MetaPropConfiguration> configurations = alienDAO.findByIds(MetaPropConfiguration.class, ids);
    for (MetaPropConfiguration configuration : configurations) {
        configurationMap.put(configuration.getId(), configuration);
    }
    return configurationMap;
}
Also used : MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration)

Example 3 with MetaPropConfiguration

use of alien4cloud.model.common.MetaPropConfiguration in project alien4cloud by alien4cloud.

the class TagConfigurationStepDefinitions method I_create_a_new_tag_with_name_and_the_target.

@Given("^I create a new tag with name \"([^\"]*)\" and the target \"([^\"]*)\"$")
public void I_create_a_new_tag_with_name_and_the_target(String name, String target) throws Throwable {
    MetaPropConfiguration tagObject = new MetaPropConfiguration();
    tagObject.setName(name);
    tagObject.setTarget(target);
    // we just save the response, we don't add the tag in the Context
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon("/rest/v1/metaproperties", JsonUtil.toString(tagObject)));
}
Also used : MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration) Given(cucumber.api.java.en.Given)

Example 4 with MetaPropConfiguration

use of alien4cloud.model.common.MetaPropConfiguration in project alien4cloud by alien4cloud.

the class MetaPropertiesService method upsertMetaProperty.

/**
 * Add or update a meta-property to a {{IMetaProperties}} resource.
 *
 * @param resource The resource for which to add or update the given meta-property.
 * @param key The id of the meta-property.
 * @param value The value of the meta-property.
 * @return
 * @throws ConstraintValueDoNotMatchPropertyTypeException
 * @throws ConstraintViolationException
 */
public ConstraintInformation upsertMetaProperty(IMetaProperties resource, String key, String value) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
    MetaPropConfiguration propertyDefinition = alienDAO.findById(MetaPropConfiguration.class, key);
    if (propertyDefinition == null) {
        throw new NotFoundException("Property update operation failed. Could not find property definition with id <" + propertyDefinition + ">.");
    }
    if (value != null) {
        // by convention updateproperty with null value => reset to default if exists
        ConstraintPropertyService.checkPropertyConstraint(key, value, propertyDefinition);
    }
    if (resource.getMetaProperties() == null) {
        resource.setMetaProperties(Maps.<String, String>newHashMap());
    } else if (resource.getMetaProperties().containsKey(key)) {
        resource.getMetaProperties().remove(key);
    }
    resource.getMetaProperties().put(key, value);
    alienDAO.save(resource);
    return null;
}
Also used : MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration) NotFoundException(alien4cloud.exception.NotFoundException)

Example 5 with MetaPropConfiguration

use of alien4cloud.model.common.MetaPropConfiguration in project alien4cloud by alien4cloud.

the class LocationsDefinitionsSteps method I_set_the_value_to_the_location_meta_property_of_the_location_of_the_orchestrator.

@When("^I set the value \"([^\"]*)\" to the location meta-property \"([^\"]*)\" of the location \"([^\"]*)\" of the orchestrator \"([^\"]*)\"$")
public void I_set_the_value_to_the_location_meta_property_of_the_location_of_the_orchestrator(String value, String metaPropertyName, String locationName, String orchestratorName) throws Throwable {
    MetaPropConfiguration propertyDefinition = Context.getInstance().getConfigurationTag(metaPropertyName);
    PropertyValidationRequest propertyCheckRequest = new PropertyValidationRequest(value, propertyDefinition.getId(), propertyDefinition, null);
    String orchestratorId = Context.getInstance().getOrchestratorId(orchestratorName);
    String locationId = getLocationIdFromName(orchestratorName, locationName);
    String restUrl = String.format("/rest/v1/orchestrators/%s/locations/%s/properties", orchestratorId, locationId);
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(restUrl, JsonUtil.toString(propertyCheckRequest)));
}
Also used : MetaPropConfiguration(alien4cloud.model.common.MetaPropConfiguration) PropertyValidationRequest(alien4cloud.rest.internal.model.PropertyValidationRequest) When(cucumber.api.java.en.When)

Aggregations

MetaPropConfiguration (alien4cloud.model.common.MetaPropConfiguration)10 NotFoundException (alien4cloud.exception.NotFoundException)3 When (cucumber.api.java.en.When)3 PropertyValidationRequest (alien4cloud.rest.internal.model.PropertyValidationRequest)2 Given (cucumber.api.java.en.Given)2 Audit (alien4cloud.audit.annotation.Audit)1 MissingCSARDependenciesException (alien4cloud.exception.MissingCSARDependenciesException)1 TagConfigurationSaveResponse (alien4cloud.rest.tags.TagConfigurationSaveResponse)1 Then (cucumber.api.java.en.Then)1 ApiOperation (io.swagger.annotations.ApiOperation)1 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1