use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class DeploymentTopologyDTOBuilder method enrichSubstitutionTypesWithServicesDependencies.
/**
* Enrich {@link LocationResourceTypes} adding types coming from on demand service resources.
*/
private void enrichSubstitutionTypesWithServicesDependencies(Collection<LocationResourceTemplate> resourceTemplates, LocationResourceTypes locationResourceTypes) {
Set<String> serviceTypes = Sets.newHashSet();
Set<CSARDependency> dependencies = Sets.newHashSet();
for (LocationResourceTemplate resourceTemplate : resourceTemplates) {
if (resourceTemplate.isService()) {
String serviceId = resourceTemplate.getId();
ServiceResource serviceResource = serviceResourceService.getOrFail(serviceId);
NodeType serviceType = ToscaContext.get(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType());
if (serviceType == null || !serviceType.getArchiveVersion().equals(serviceResource.getNodeInstance().getTypeVersion())) {
serviceType = toscaTypeSearchService.findOrFail(NodeType.class, serviceResource.getNodeInstance().getNodeTemplate().getType(), serviceResource.getNodeInstance().getTypeVersion());
}
dependencies.addAll(csarDependencyLoader.getDependencies(serviceType.getArchiveName(), serviceType.getArchiveVersion()));
dependencies.add(new CSARDependency(serviceType.getArchiveName(), serviceType.getArchiveVersion()));
serviceTypes.add(serviceResource.getNodeInstance().getNodeTemplate().getType());
}
}
locationResourceService.fillLocationResourceTypes(serviceTypes, locationResourceTypes, dependencies);
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class NodeMatcherService method populateLocationResourcesWithServiceResource.
/**
* Populate this {@link LocationResources} using these {@link ServiceResource}s in order to make them available as {@link LocationResourceTemplate} for
* matching purpose.
*
* TODO: Improve this ugly code to put ServiceResource in LocationResourceTemplates.
*/
private void populateLocationResourcesWithServiceResource(LocationResources locationResources, List<ServiceResource> services, String locationId) {
for (ServiceResource serviceResource : services) {
LocationResourceTemplate lrt = new LocationResourceTemplate();
lrt.setService(true);
lrt.setEnabled(true);
// for a service we also want to display the version, so just add it to the name
lrt.setName(serviceResource.getName() + ":" + serviceResource.getVersion());
lrt.setId(serviceResource.getId());
ServiceNodeTemplate serviceNodeTemplate = new ServiceNodeTemplate(serviceResource.getNodeInstance());
lrt.setTemplate(serviceNodeTemplate);
lrt.setLocationId(locationId);
String serviceTypeName = serviceResource.getNodeInstance().getNodeTemplate().getType();
List<String> types = Lists.newArrayList(serviceTypeName);
lrt.setTypes(types);
NodeType serviceType = toscaTypeSearchService.findOrFail(NodeType.class, serviceTypeName, serviceResource.getNodeInstance().getTypeVersion());
types.addAll(serviceType.getDerivedFrom());
locationResources.getNodeTypes().put(serviceTypeName, serviceType);
Csar csar = toscaTypeSearchService.getArchive(serviceType.getArchiveName(), serviceType.getArchiveVersion());
Set<CSARDependency> dependencies = Sets.newHashSet();
if (csar.getDependencies() != null) {
dependencies.addAll(csar.getDependencies());
}
dependencies.add(new CSARDependency(csar.getName(), csar.getVersion()));
if (serviceType.getCapabilities() != null && !serviceType.getCapabilities().isEmpty()) {
for (CapabilityDefinition capabilityDefinition : serviceType.getCapabilities()) {
locationResources.getCapabilityTypes().put(capabilityDefinition.getType(), csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), dependencies));
}
}
locationResources.getNodeTemplates().add(lrt);
}
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ServiceResourceRelationshipService method processService.
private void processService(PaaSNodeTemplate paaSNodeTemplate) {
ServiceNodeTemplate serviceNodeTemplate = (ServiceNodeTemplate) paaSNodeTemplate.getTemplate();
ServiceResource serviceResource = serviceResourceService.getOrFail(serviceNodeTemplate.getServiceResourceId());
for (PaaSRelationshipTemplate paaSRelationshipTemplate : paaSNodeTemplate.getRelationshipTemplates()) {
Interface templateInterface = safe(paaSRelationshipTemplate.getInterfaces()).get(ToscaRelationshipLifecycleConstants.CONFIGURE);
if (templateInterface != null) {
if (paaSRelationshipTemplate.getSource().equals(paaSNodeTemplate.getId())) {
processSourceOperations(paaSRelationshipTemplate, serviceResource, templateInterface);
} else {
processTargetOperations(paaSRelationshipTemplate, serviceResource, templateInterface);
}
}
}
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class NodeMatchingReplaceModifier method processServiceResourceReplacement.
@Override
protected void processServiceResourceReplacement(Topology topology, Map<String, NodeTemplate> topologyTemplateMap, String nodeId, String serviceResourceId) {
ServiceResource serviceResource = getServiceResourceService().getOrFail(serviceResourceId);
NodeTemplate serviceNodeTemplate = serviceResource.getNodeInstance().getNodeTemplate();
ServiceNodeTemplate substitutionNodeTemplate = new ServiceNodeTemplate(serviceNodeTemplate.getType(), serviceNodeTemplate.getProperties(), serviceNodeTemplate.getAttributes(), serviceNodeTemplate.getRelationships(), serviceNodeTemplate.getRequirements(), serviceNodeTemplate.getCapabilities(), serviceNodeTemplate.getInterfaces(), serviceNodeTemplate.getArtifacts());
substitutionNodeTemplate.setServiceResourceId(serviceResource.getId());
substitutionNodeTemplate.setAttributeValues(serviceResource.getNodeInstance().getAttributeValues());
NodeTemplate abstractTopologyNode = topologyTemplateMap.put(nodeId, substitutionNodeTemplate);
substitutionNodeTemplate.setName(abstractTopologyNode.getName());
substitutionNodeTemplate.setRelationships(abstractTopologyNode.getRelationships());
// add all the necessary dependencies to the topology
Csar csar = getToscaTypeSearchService().getArchive(serviceResource.getDependency().getName(), serviceResource.getDependency().getVersion());
Set<CSARDependency> dependencies = Sets.newHashSet();
if (csar.getDependencies() != null) {
dependencies.addAll(csar.getDependencies());
}
dependencies.add(new CSARDependency(csar.getName(), csar.getVersion()));
topology.getDependencies().addAll(dependencies);
}
use of alien4cloud.model.service.ServiceResource in project alien4cloud by alien4cloud.
the class ManagedServiceResourceEventService method eventHappened.
@Override
public void eventHappened(AbstractMonitorEvent event) {
String state = getInstanceStateFromDeploymentStatus(((PaaSDeploymentStatusMonitorEvent) event).getDeploymentStatus());
if (state == null) {
// Ignored.
return;
}
ServiceResource serviceResource = alienDAO.buildQuery(ServiceResource.class).setFilters(fromKeyValueCouples("deploymentId", event.getDeploymentId())).prepareSearch().find();
if (serviceResource == null) {
// No service resources matching this deployment.
return;
}
String currentState = serviceResource.getNodeInstance().getAttributeValues().get(ToscaNodeLifecycleConstants.ATT_STATE);
if (state.equals(currentState)) {
// nothing changed
return;
}
if (ToscaNodeLifecycleConstants.INITIAL.equals(state)) {
// Reset service node attribute and properties.
resetRunningServiceResource(serviceResource);
} else {
// Set service node attribute and properties.
updateRunningService(serviceResource, event.getDeploymentId(), state);
}
}
Aggregations