use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class LocationResourceService method saveResource.
/*
* (non-Javadoc)
*
* @see
* alien4cloud.orchestrators.locations.services.ILocationResourceService#saveResource(alien4cloud.model.orchestrators.locations.LocationResourceTemplate)
*/
@Override
public void saveResource(AbstractLocationResourceTemplate resourceTemplate) {
Location location = locationService.getOrFail(resourceTemplate.getLocationId());
saveResource(location, resourceTemplate);
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class LocationResourceService method deleteGeneratedResources.
/*
* (non-Javadoc)
*
* @see alien4cloud.orchestrators.locations.services.ILocationResourceService#deleteGeneratedResources(java.lang.String)
*/
@Override
public void deleteGeneratedResources(String locationId) {
QueryBuilder locationIdQuery = QueryBuilders.termQuery("locationId", locationId);
QueryBuilder generatedFieldQuery = QueryBuilders.termQuery("generated", true);
// QueryBuilder builder = QueryBuilders.filteredQuery(locationIdQuery, filterBuilder);
QueryBuilder builder = QueryBuilders.boolQuery().must(locationIdQuery).must(generatedFieldQuery);
Location location = locationService.getOrFail(locationId);
alienDAO.delete(LocationResourceTemplate.class, builder);
alienDAO.save(location);
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class LocationService method delete.
/**
* Delete a locations.
*
* @param id id of the locations to delete.
* @return true if the location was successfully , false if not.
*/
public synchronized boolean delete(String orchestratorId, String id) {
Orchestrator orchestrator = orchestratorService.getOrFail(orchestratorId);
if (alienDAO.count(Deployment.class, null, fromKeyValueCouples("orchestratorId", orchestratorId, "locationIds", id, "endDate", null)) > 0) {
return false;
}
Location location = getOrFail(id);
publisher.publishEvent(new BeforeLocationDeleted(this, location.getId()));
// delete all location resources for the given location
alienDAO.delete(LocationResourceTemplate.class, QueryBuilders.termQuery("locationId", id));
// delete the location
alienDAO.delete(Location.class, id);
// delete all archives associated with this location only, if possible of course
Map<Csar, List<Usage>> usages = locationArchiveIndexer.deleteArchives(orchestrator, location);
if (MapUtils.isNotEmpty(usages)) {
// TODO what to do when some archives were not deleted?
log.warn("Some archives for location were not deleted! \n" + usages);
}
publisher.publishEvent(new AfterLocationDeleted(this, location.getId()));
return true;
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class LocationService method create.
/**
* Add a new locations for a given orchestrator.
*/
public String create(String orchestratorId, String locationName, String infrastructureType) {
Orchestrator orchestrator = orchestratorService.getOrFail(orchestratorId);
if (!OrchestratorState.CONNECTED.equals(orchestrator.getState())) {
// we cannot configure locations for orchestrator that are not connected.
// TODO throw exception
}
ensureMultipleLocations(orchestratorId);
Location location = new Location();
location.setId(UUID.randomUUID().toString());
location.setName(locationName);
location.setOrchestratorId(orchestratorId);
createLocation(orchestrator, location, infrastructureType);
publisher.publishEvent(new AfterLocationCreated(this, location));
return location.getId();
}
use of alien4cloud.model.orchestrators.locations.Location in project alien4cloud by alien4cloud.
the class LocationService method findByIds.
/**
* Retrieve location given a list of ids, and a specific context
*
* @param fetchContext The fetch context to recover only the required field (Note that this should be simplified to directly use the given field...).
* @param ids array of id of the applications to find
* @return Map of locations that has the given ids and (key is application Id), or null if no location matching the
* request is found.
*/
public Map<String, Location> findByIds(String fetchContext, String... ids) {
List<Location> results = alienDAO.findByIdsWithContext(Location.class, fetchContext, ids);
if (results == null) {
return null;
}
Map<String, Location> locations = Maps.newHashMap();
for (Location location : results) {
locations.put(location.getId(), location);
}
return locations.isEmpty() ? null : locations;
}
Aggregations