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());
}
}
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;
}
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)));
}
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;
}
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)));
}
Aggregations