use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.
the class OrchestratorStateService method disable.
/**
* Disable an orchestrator.
*
* @param orchestrator The orchestrator to disable.
* @param force If true the orchestrator is disabled even if some deployments are currently running.
*/
public synchronized List<Usage> disable(Orchestrator orchestrator, boolean force) {
if (!force) {
// If there is at least one active deployment.
GetMultipleDataResult<Deployment> result = alienDAO.buildQuery(Deployment.class).setFilters(MapUtil.newHashMap(new String[] { "orchestratorId", "endDate" }, new String[][] { new String[] { orchestrator.getId() }, new String[] { null } })).prepareSearch().setFieldSort("_timestamp", true).search(0, 1);
// TODO place a lock to avoid deployments during the disabling of the orchestrator.
if (result.getData().length > 0) {
List<Usage> usages = generateDeploymentUsages(result.getData());
return usages;
}
}
try {
// unregister the orchestrator.
IOrchestratorPlugin orchestratorInstance = orchestratorPluginService.unregister(orchestrator.getId());
if (orchestratorInstance != null) {
IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
orchestratorFactory.destroy(orchestratorInstance);
}
} catch (Exception e) {
log.info("Unable to destroy orchestrator, it may not be created yet", e);
} finally {
// Mark the orchestrator as disabled
orchestrator.setState(OrchestratorState.DISABLED);
alienDAO.save(orchestrator);
}
return null;
}
use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.
the class CloudServiceArchiveController method delete.
@ApiOperation(value = "Delete a CSAR given its id.")
@RequestMapping(value = "/{csarId:.+?}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<List<Usage>> delete(@PathVariable String csarId) {
Csar csar = csarService.getOrFail(csarId);
csarAuthorizationFilter.checkWriteAccess(csar);
List<Usage> relatedResourceList = csarService.deleteCsarWithElements(csar);
if (CollectionUtils.isNotEmpty(relatedResourceList)) {
String errorMessage = "The csar named <" + csar.getName() + "> in version <" + csar.getVersion() + "> can not be deleted since it is referenced by other resources";
return RestResponseBuilder.<List<Usage>>builder().data(relatedResourceList).error(RestErrorBuilder.builder(RestErrorCode.DELETE_REFERENCED_OBJECT_ERROR).message(errorMessage).build()).build();
}
return RestResponseBuilder.<List<Usage>>builder().build();
}
use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.
the class CsarService method generateTopologiesInfo.
/**
* Generate resources (application or template) related to a topology list
*
* @param topologies
* @return
*/
public List<Usage> generateTopologiesInfo(Topology[] topologies) {
List<Usage> resourceList = Lists.newArrayList();
List<Csar> topologiesCsar = getTopologiesCsar(topologies);
for (Csar csar : topologiesCsar) {
if (Objects.equals(csar.getDelegateType(), ArchiveDelegateType.APPLICATION.toString())) {
// get the related application
Application application = applicationService.checkAndGetApplication(csar.getDelegateId());
resourceList.add(new Usage(application.getName(), csar.getDelegateType(), csar.getDelegateId(), csar.getWorkspace()));
} else {
resourceList.add(new Usage(csar.getName() + "[" + csar.getVersion() + "]", "topologyTemplate", csar.getId(), csar.getWorkspace()));
}
}
return resourceList;
}
use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.
the class ArchiveProviderPluginCallBack method deleteArchives.
private Map<Csar, List<Usage>> deleteArchives(Collection<PluginArchive> pluginArchives) {
Map<Csar, List<Usage>> usages = Maps.newHashMap();
for (PluginArchive pluginArchive : safe(pluginArchives)) {
Csar csar = pluginArchive.getArchive().getArchive();
List<Usage> csarUsage = csarService.deleteCsarWithElements(csar);
// TODO push delete event
if (CollectionUtils.isNotEmpty(csarUsage)) {
usages.put(csar, csarUsage);
}
}
return usages.isEmpty() ? null : usages;
}
use of alien4cloud.model.common.Usage in project alien4cloud by alien4cloud.
the class CrudCSARSStepDefinition method I_should_have_a_delete_csar_response_with_related_resources.
@Then("^The delete csar response should contains the following related resources$")
public void I_should_have_a_delete_csar_response_with_related_resources(DataTable usageDT) throws Throwable {
RestResponse<?> restResponse = JsonUtil.read(Context.getInstance().getRestResponse());
Assert.assertNotNull(restResponse);
List<Usage> resultData = JsonUtil.toList(JsonUtil.toString(restResponse.getData()), Usage.class);
boolean isPresent;
for (Usage usage : resultData) {
isPresent = false;
for (DataTableRow row : usageDT.getGherkinRows()) {
if (usage.getResourceName().equals(row.getCells().get(0)) && usage.getResourceType().equals(row.getCells().get(1))) {
isPresent = true;
break;
}
}
if (!isPresent) {
Assert.assertFalse("Test failed : one of expected usage is not found : " + usage.getResourceName() + " : " + usage.getResourceType(), true);
}
}
}
Aggregations