use of org.opentosca.container.api.dto.plan.PlanDTO in project container by OpenTOSCA.
the class PlanService method invokePlan.
public String invokePlan(Csar csar, TServiceTemplate serviceTemplate, Long serviceTemplateInstanceId, String planId, List<TParameter> parameters, PlanType... planTypes) {
TPlan plan = csar.plans().stream().filter(tplan -> tplan.getId().equals(planId) && Arrays.stream(planTypes).anyMatch(pt -> tplan.getPlanType().equals(pt.toString()))).findFirst().orElseThrow(() -> new NotFoundException("Plan \"" + planId + "\" could not be found"));
final PlanDTO dto = new PlanDTO(plan);
dto.setId(plan.getId());
enhanceInputParameters(parameters);
dto.setInputParameters(parameters);
final String correlationId = controlService.invokePlanInvocation(csar.id(), serviceTemplate, serviceTemplateInstanceId, PlanDTO.Converter.convert(dto));
if (PlanType.fromString(plan.getPlanType()).equals(PlanType.BUILD) && Boolean.parseBoolean(Settings.OPENTOSCA_DEPLOYMENT_TESTS)) {
logger.debug("Plan \"{}\" is a build plan, so we schedule deployment tests...", plan.getName());
this.deploymentTestService.runAfterPlan(csar.id(), correlationId);
}
return correlationId;
}
use of org.opentosca.container.api.dto.plan.PlanDTO in project container by OpenTOSCA.
the class BoundaryDefinitionController method getBoundaryDefinitionInterface.
@GET
@Path("/interfaces/{name}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "Get an interface of a service template", response = InterfaceDTO.class)
public Response getBoundaryDefinitionInterface(@ApiParam("interface name") @PathParam("name") final String name, @ApiParam("ID of CSAR") @PathParam("csar") final String csarId, @ApiParam("qualified name of the service template") @PathParam("servicetemplate") final String servicetemplate) {
logger.debug("Invoking getBoundaryDefinitionInterface");
final Csar csar = this.storage.findById(new CsarId(csarId));
final TServiceTemplate serviceTemplate;
try {
serviceTemplate = ToscaEngine.resolveServiceTemplate(csar, servicetemplate);
} catch (org.opentosca.container.core.common.NotFoundException e) {
throw new NotFoundException(e);
}
@SuppressWarnings("null") final List<TExportedOperation> operations = Optional.ofNullable(serviceTemplate).map(TServiceTemplate::getBoundaryDefinitions).map(TBoundaryDefinitions::getInterfaces).stream().flatMap(Collection::stream).filter(iface -> iface.getIdFromIdOrNameField().equals(name)).findFirst().map(TExportedInterface::getOperation).orElse(Collections.emptyList());
logger.debug("Found <{}> operation(s) for Interface \"{}\" in Service Template \"{}\" of CSAR \"{}\" ", operations.size(), name, servicetemplate, csar.id().csarName());
Collection<ServiceTemplateInstance> serviceInstances = serviceTemplateInstanceRepository.findByTemplateId(servicetemplate);
final Map<String, OperationDTO> ops = operations.stream().map(o -> {
final OperationDTO op = new OperationDTO();
op.setName(o.getName());
op.setNodeOperation(NodeOperationDTO.Converter.convert(o.getNodeOperation()));
op.setRelationshipOperation(o.getRelationshipOperation());
if (o.getPlan() != null) {
final PlanDTO plan = new PlanDTO((TPlan) o.getPlan().getPlanRef());
op.setPlan(plan);
// Compute the according URL for the Build or Management Plan
URI planUrl;
if (PlanType.BUILD.toString().equals(plan.getPlanType())) {
// If it's a build plan
planUrl = this.uriInfo.getBaseUriBuilder().path("/csars/{csar}/servicetemplates/{servicetemplate}/buildplans/{buildplan}").build(csar.id().csarName(), servicetemplate, plan.getId());
plan.add(Link.fromUri(UriUtil.encode(planUrl)).rel("self").build());
op.add(Link.fromUri(UriUtil.encode(planUrl)).rel("plan").build());
} else {
// ... else we assume it's a management plan
for (ServiceTemplateInstance serviceInstance : serviceInstances) {
planUrl = this.uriInfo.getBaseUriBuilder().path("/csars/{csar}/servicetemplates/{servicetemplate}/instances/{serviceinstance}/managementplans/{managementplan}").build(csar.id().csarName(), servicetemplate, serviceInstance.getId(), plan.getId());
op.add(Link.fromUri(UriUtil.encode(planUrl)).rel("plan").build());
plan.add(Link.fromUri(UriUtil.encode(planUrl)).rel("self").build());
}
}
}
return op;
}).collect(Collectors.toMap(OperationDTO::getName, t -> t));
final InterfaceDTO dto = new InterfaceDTO();
dto.setName(name);
dto.setOperations(ops);
dto.add(UriUtil.generateSelfLink(this.uriInfo));
return Response.ok(dto).build();
}
use of org.opentosca.container.api.dto.plan.PlanDTO in project container by OpenTOSCA.
the class BuildPlanController method getBuildPlans.
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "Get build plans of service template", response = PlanListDTO.class)
public Response getBuildPlans(@Context final UriInfo uriInfo) {
LOGGER.debug("Invoking getBuildPlans");
PlanListDTO list = new PlanListDTO();
csar.plans().stream().filter(tplan -> tplan.getPlanType().equals(PLAN_TYPE.toString())).map(p -> {
final PlanDTO plan = new PlanDTO(p);
plan.add(Link.fromUri(UriUtil.encode(uriInfo.getAbsolutePathBuilder().path(plan.getId()).path("instances").build())).rel("instances").build());
plan.add(Link.fromUri(UriUtil.encode(uriInfo.getAbsolutePathBuilder().path(plan.getId()).build())).rel("self").build());
return plan;
}).forEach(list::add);
list.add(Link.fromUri(UriUtil.encode(uriInfo.getAbsolutePath())).rel("self").build());
return Response.ok(list).build();
}
use of org.opentosca.container.api.dto.plan.PlanDTO in project container by OpenTOSCA.
the class BuildPlanController method getBuildPlan.
@GET
@Path("/{plan}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "Get a build plan", response = PlanDTO.class)
public Response getBuildPlan(@ApiParam("ID of build plan") @PathParam("plan") final String plan, @Context final UriInfo uriInfo) {
PlanDTO dto = Utils.getPlanDto(csar, ALL_PLAN_TYPES, plan);
dto.add(Link.fromUri(UriUtil.encode(uriInfo.getAbsolutePathBuilder().path("instances").build())).rel("instances").build());
dto.add(Link.fromUri(UriUtil.encode(uriInfo.getAbsolutePath())).rel("self").build());
return Response.ok(dto).build();
}
use of org.opentosca.container.api.dto.plan.PlanDTO in project container by OpenTOSCA.
the class ManagementPlanController method getManagementPlans.
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@ApiOperation(value = "Get management plans", response = PlanListDTO.class)
public Response getManagementPlans(@Context final UriInfo uriInfo) {
PlanListDTO list = new PlanListDTO();
csar.plans().stream().filter(tplan -> Arrays.stream(planTypes).anyMatch(pt -> tplan.getPlanType().equals(pt.toString()))).map(p -> {
final PlanDTO plan = new PlanDTO(p);
plan.add(Link.fromUri(UriUtil.encode(uriInfo.getAbsolutePathBuilder().path(plan.getId()).path("instances").build())).rel("instances").build());
plan.add(Link.fromUri(UriUtil.encode(uriInfo.getAbsolutePathBuilder().path(plan.getId()).build())).rel("self").build());
return plan;
}).forEach(list::add);
list.add(Link.fromUri(UriUtil.encode(uriInfo.getAbsolutePath())).rel("self").build());
return Response.ok(list).build();
}
Aggregations