Search in sources :

Example 1 with Usage

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;
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) Usage(alien4cloud.model.common.Usage) Deployment(alien4cloud.model.deployment.Deployment) AlreadyExistException(alien4cloud.exception.AlreadyExistException) IOException(java.io.IOException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 2 with Usage

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();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Usage(alien4cloud.model.common.Usage) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Usage

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;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Usage(alien4cloud.model.common.Usage) Application(alien4cloud.model.application.Application)

Example 4 with Usage

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;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Usage(alien4cloud.model.common.Usage) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) List(java.util.List)

Example 5 with Usage

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);
        }
    }
}
Also used : Usage(alien4cloud.model.common.Usage) DataTableRow(gherkin.formatter.model.DataTableRow) Then(cucumber.api.java.en.Then)

Aggregations

Usage (alien4cloud.model.common.Usage)16 Csar (org.alien4cloud.tosca.model.Csar)7 Application (alien4cloud.model.application.Application)4 Deployment (alien4cloud.model.deployment.Deployment)3 Location (alien4cloud.model.orchestrators.locations.Location)3 ApiOperation (io.swagger.annotations.ApiOperation)3 List (java.util.List)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ServiceResource (alien4cloud.model.service.ServiceResource)2 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)2 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)2 ServiceUsageRequestEvent (org.alien4cloud.alm.service.events.ServiceUsageRequestEvent)2 EventListener (org.springframework.context.event.EventListener)2 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)1 Audit (alien4cloud.audit.annotation.Audit)1 FilterUtil.fromKeyValueCouples (alien4cloud.dao.FilterUtil.fromKeyValueCouples)1 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)1 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 LocationArchiveDeleteRequested (alien4cloud.events.LocationArchiveDeleteRequested)1