use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class DeploymentController method search.
/**
* Search for deployments
*
* @return A rest response that contains a {@link FacetedSearchResult} containing deployments, including if asked some details of the related applications..
*/
@ApiOperation(value = "Search for deployments", notes = "Returns a search result with that contains deployments matching the request.")
@RequestMapping(value = "/search", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<FacetedSearchResult> search(@ApiParam(value = "Query text.") @RequestParam(required = false) String query, @ApiParam(value = "Query from the given index.") @RequestParam(required = false, defaultValue = "0") int from, @ApiParam(value = "Maximum number of results to retrieve.") @RequestParam(required = false, defaultValue = "50") int size, @ApiParam(value = "Id of the orchestrator for which to get deployments. If not provided, get deployments for all orchestrators") @RequestParam(required = false) String orchestratorId, @ApiParam(value = "Id of the application for which to get deployments. if not provided, get deployments for all applications") @RequestParam(required = false) String sourceId, @ApiParam(value = "Id of the environment for which to get deployments. if not provided, get deployments without filtering by environment") @RequestParam(required = false) String environmentId, @ApiParam(value = "include or not the source (application or csar) summary in the results") @RequestParam(required = false, defaultValue = "false") boolean includeSourceSummary) {
FacetedSearchResult searchResult = deploymentService.searchDeployments(query, orchestratorId, environmentId, sourceId, from, size);
List<DeploymentDTO> deploymentsDTOS = buildDeploymentsDTOS(includeSourceSummary, (Deployment[]) searchResult.getData());
searchResult.setData(deploymentsDTOS.toArray());
return RestResponseBuilder.<FacetedSearchResult>builder().data(searchResult).build();
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class DeploymentEventHandler method send.
protected void send(AbstractMonitorEvent event) {
String eventType = MappingBuilder.indexTypeFromClass(event.getClass());
String topicName = TOPIC_PREFIX + '/' + event.getDeploymentId() + '/' + eventType;
dispatchEvent(event, topicName);
if (event instanceof PaaSDeploymentStatusMonitorEvent) {
Deployment deployment = alienDAO.findById(Deployment.class, event.getDeploymentId());
if (deployment != null && deployment.getEnvironmentId() != null) {
// dispatch an event on the environment topic
topicName = ENV_TOPIC_PREFIX + "/" + deployment.getEnvironmentId();
dispatchEvent(event, topicName);
}
}
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class DeploymentEventHandler method checkDeploymentAuthorization.
private void checkDeploymentAuthorization(Authentication authentication, User a4cUser, String deploymentId) {
Deployment deployment = alienDAO.findById(Deployment.class, deploymentId);
switch(deployment.getSourceType()) {
case APPLICATION:
// check if the user has right for the environment associated with the deployment.
ApplicationEnvironment environment = alienDAO.findById(ApplicationEnvironment.class, deployment.getEnvironmentId());
if (environment == null) {
log.error("Environment with id [{}] do not exist any more for deployment [{}]", deployment.getEnvironmentId(), deployment.getId());
throw new NotFoundException("Environment with id [" + deployment.getEnvironmentId() + "] do not exist any more for deployment [" + deployment.getId() + "]");
}
AuthorizationUtil.checkAuthorization(a4cUser, environment, ApplicationRole.APPLICATION_MANAGER, ApplicationEnvironmentRole.values());
break;
case CSAR:
AuthorizationUtil.checkHasOneRoleIn(authentication, Role.COMPONENTS_MANAGER);
}
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class WorkflowEventHandler method send.
protected void send(AbstractMonitorEvent event) {
String eventType = MappingBuilder.indexTypeFromClass(event.getClass());
String topicName = TOPIC_PREFIX + '/' + event.getDeploymentId() + '/' + eventType;
if (log.isDebugEnabled()) {
log.debug("Send [" + event.getClass().getSimpleName() + "] to [" + topicName + "]: " + event);
}
template.convertAndSend(topicName, event);
if (event instanceof PaaSWorkflowMonitorEvent) {
Deployment deployment = alienDAO.findById(Deployment.class, event.getDeploymentId());
if (deployment != null) {
PaaSWorkflowMonitorEvent pwme = (PaaSWorkflowMonitorEvent) event;
if (log.isDebugEnabled()) {
log.debug("Workflow {} started with executionId {} (subkworkflow: {})", pwme.getWorkflowId(), pwme.getExecutionId(), pwme.getSubworkflow());
}
String workflowId = pwme.getWorkflowId();
if (pwme.getSubworkflow() != null) {
workflowId = pwme.getSubworkflow();
}
updateDeploymentExecutionId(deployment, workflowId, pwme.getExecutionId());
}
}
}
use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.
the class BlockStorageEventHandler method updateApplicationTopology.
private void updateApplicationTopology(PaaSInstancePersistentResourceMonitorEvent persistentResourceEvent, final Map<String, Object> persistentProperties) {
Deployment deployment = deploymentService.get(persistentResourceEvent.getDeploymentId());
String topologyId = deployment.getSourceId() + ":" + deployment.getVersionId();
Topology topology = topoServiceCore.getOrFail(topologyId);
// The deployment topology may have changed and the node removed, in such situations there is nothing to update as the block won't be reused.
NodeTemplate nodeTemplate;
try {
nodeTemplate = TopologyUtils.getNodeTemplate(topology, persistentResourceEvent.getNodeTemplateId());
} catch (NotFoundException e) {
log.warn("Fail to update persistent resource for node {}", persistentResourceEvent.getNodeTemplateId(), e);
return;
}
for (String propertyName : persistentProperties.keySet()) {
Object propertyValue = persistentProperties.get(propertyName);
AbstractPropertyValue abstractPropertyValue = nodeTemplate.getProperties().get(propertyName);
if (abstractPropertyValue != null && abstractPropertyValue instanceof FunctionPropertyValue) {
// the value is set in the topology
FunctionPropertyValue function = (FunctionPropertyValue) abstractPropertyValue;
if (function.getFunction().equals(ToscaFunctionConstants.GET_INPUT) && propertyValue instanceof String) {
DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(deployment.getVersionId(), deployment.getEnvironmentId()));
// the value is set in the input (deployment setup)
log.info("Updating deploymentsetup [ {} ] input properties [ {} ] to add a new VolumeId", deploymentInputs.getId(), function.getTemplateName());
log.debug("Property [ {} ] to update: [ {} ]. New value is [ {} ]", propertyName, persistentResourceEvent.getPersistentProperties().get(propertyName), propertyValue);
deploymentInputs.getInputs().put(function.getTemplateName(), new ScalarPropertyValue((String) propertyValue));
deploymentConfigurationDao.save(deploymentInputs);
} else {
// this is not supported / print a warning
log.warn("Failed to store the id of the created block storage [ {} ] for deployment [ {} ] application [ {} ] environment [ {} ]");
return;
}
} else {
DeploymentMatchingConfiguration matchingConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(deployment.getVersionId(), deployment.getEnvironmentId()));
log.info("Updating deployment topology: Persistent resource property [ {} ] for node template <{}.{}> to add a value", propertyName, matchingConfiguration.getId(), persistentResourceEvent.getNodeTemplateId());
log.debug("Value to add: [ {} ]. New value is [ {} ]", persistentResourceEvent.getPersistentProperties().get(propertyName), propertyValue);
matchingConfiguration.getMatchedNodesConfiguration().get(persistentResourceEvent.getNodeTemplateId()).getProperties().put(propertyName, getPropertyValue(propertyValue));
deploymentConfigurationDao.save(matchingConfiguration);
}
}
}
Aggregations