Search in sources :

Example 1 with PlanDTO

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;
}
Also used : PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) TPlan(org.eclipse.winery.model.tosca.TPlan) NotFoundException(javax.ws.rs.NotFoundException)

Example 2 with PlanDTO

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();
}
Also used : Produces(javax.ws.rs.Produces) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) PlanType(org.opentosca.container.core.next.model.PlanType) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) ToscaEngine(org.opentosca.container.core.engine.ToscaEngine) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) ServiceTemplateInstanceRepository(org.opentosca.container.core.next.repository.ServiceTemplateInstanceRepository) Map(java.util.Map) URI(java.net.URI) CsarId(org.opentosca.container.core.model.csar.CsarId) Context(javax.ws.rs.core.Context) InterfaceDTO(org.opentosca.container.api.dto.boundarydefinitions.InterfaceDTO) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) Objects(java.util.Objects) PropertiesDTO(org.opentosca.container.api.dto.boundarydefinitions.PropertiesDTO) List(java.util.List) Response(javax.ws.rs.core.Response) TPlan(org.eclipse.winery.model.tosca.TPlan) PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) Optional(java.util.Optional) Request(javax.ws.rs.core.Request) UriInfo(javax.ws.rs.core.UriInfo) UriUtil(org.opentosca.container.core.common.uri.UriUtil) Link(javax.ws.rs.core.Link) InterfaceListDTO(org.opentosca.container.api.dto.boundarydefinitions.InterfaceListDTO) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) PropertyMappingDTO(org.opentosca.container.api.dto.boundarydefinitions.PropertyMappingDTO) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) Inject(javax.inject.Inject) TExportedInterface(org.eclipse.winery.model.tosca.TExportedInterface) ResourceSupport(org.opentosca.container.api.dto.ResourceSupport) Api(io.swagger.annotations.Api) Csar(org.opentosca.container.core.model.csar.Csar) NodeOperationDTO(org.opentosca.container.api.dto.NodeOperationDTO) Logger(org.slf4j.Logger) CsarStorageService(org.opentosca.container.core.service.CsarStorageService) TPropertyMapping(org.eclipse.winery.model.tosca.TPropertyMapping) Component(org.springframework.stereotype.Component) OperationDTO(org.opentosca.container.api.dto.boundarydefinitions.OperationDTO) Collections(java.util.Collections) TExportedOperation(org.eclipse.winery.model.tosca.TExportedOperation) Csar(org.opentosca.container.core.model.csar.Csar) NotFoundException(javax.ws.rs.NotFoundException) CsarId(org.opentosca.container.core.model.csar.CsarId) TBoundaryDefinitions(org.eclipse.winery.model.tosca.TBoundaryDefinitions) NodeOperationDTO(org.opentosca.container.api.dto.NodeOperationDTO) OperationDTO(org.opentosca.container.api.dto.boundarydefinitions.OperationDTO) URI(java.net.URI) PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) TPlan(org.eclipse.winery.model.tosca.TPlan) Collection(java.util.Collection) ServiceTemplateInstance(org.opentosca.container.core.next.model.ServiceTemplateInstance) InterfaceDTO(org.opentosca.container.api.dto.boundarydefinitions.InterfaceDTO) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) TExportedOperation(org.eclipse.winery.model.tosca.TExportedOperation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with PlanDTO

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();
}
Also used : PlanListDTO(org.opentosca.container.api.dto.plan.PlanListDTO) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) TParameter(org.opentosca.container.core.extension.TParameter) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) PlanType(org.opentosca.container.core.next.model.PlanType) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) PlanInvokerService(org.opentosca.container.api.service.PlanInvokerService) PlanInstanceService(org.opentosca.container.core.next.services.instances.PlanInstanceService) URI(java.net.URI) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) PlanInstanceEventDTO(org.opentosca.container.api.dto.plan.PlanInstanceEventDTO) Csar(org.opentosca.container.core.model.csar.Csar) PlanInstance(org.opentosca.container.core.next.model.PlanInstance) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) PlanInstanceListDTO(org.opentosca.container.api.dto.plan.PlanInstanceListDTO) Logger(org.slf4j.Logger) PlanInstanceState(org.opentosca.container.core.next.model.PlanInstanceState) Collection(java.util.Collection) CreatePlanInstanceLogEntryRequest(org.opentosca.container.api.dto.request.CreatePlanInstanceLogEntryRequest) Utils(org.opentosca.container.api.util.Utils) List(java.util.List) Response(javax.ws.rs.core.Response) PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) PlanInstanceDTO(org.opentosca.container.api.dto.plan.PlanInstanceDTO) PUT(javax.ws.rs.PUT) PlanInstanceEventListDTO(org.opentosca.container.api.dto.plan.PlanInstanceEventListDTO) PlanInstanceEvent(org.opentosca.container.core.next.model.PlanInstanceEvent) UriInfo(javax.ws.rs.core.UriInfo) UriUtil(org.opentosca.container.core.common.uri.UriUtil) Link(javax.ws.rs.core.Link) PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) PlanListDTO(org.opentosca.container.api.dto.plan.PlanListDTO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with PlanDTO

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();
}
Also used : PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with PlanDTO

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();
}
Also used : PlanListDTO(org.opentosca.container.api.dto.plan.PlanListDTO) Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) TParameter(org.opentosca.container.core.extension.TParameter) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) PlanType(org.opentosca.container.core.next.model.PlanType) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) PlanInvokerService(org.opentosca.container.api.service.PlanInvokerService) PlanInstanceService(org.opentosca.container.core.next.services.instances.PlanInstanceService) URI(java.net.URI) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) PlanInstanceEventDTO(org.opentosca.container.api.dto.plan.PlanInstanceEventDTO) Csar(org.opentosca.container.core.model.csar.Csar) PlanInstance(org.opentosca.container.core.next.model.PlanInstance) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) PlanInstanceListDTO(org.opentosca.container.api.dto.plan.PlanInstanceListDTO) Logger(org.slf4j.Logger) PlanInstanceState(org.opentosca.container.core.next.model.PlanInstanceState) NotFoundException(org.opentosca.container.core.common.NotFoundException) CreatePlanInstanceLogEntryRequest(org.opentosca.container.api.dto.request.CreatePlanInstanceLogEntryRequest) Utils(org.opentosca.container.api.util.Utils) List(java.util.List) Response(javax.ws.rs.core.Response) PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) PlanInstanceDTO(org.opentosca.container.api.dto.plan.PlanInstanceDTO) PUT(javax.ws.rs.PUT) PlanInstanceEventListDTO(org.opentosca.container.api.dto.plan.PlanInstanceEventListDTO) PlanInstanceEvent(org.opentosca.container.core.next.model.PlanInstanceEvent) UriInfo(javax.ws.rs.core.UriInfo) UriUtil(org.opentosca.container.core.common.uri.UriUtil) Link(javax.ws.rs.core.Link) PlanDTO(org.opentosca.container.api.dto.plan.PlanDTO) PlanListDTO(org.opentosca.container.api.dto.plan.PlanListDTO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

PlanDTO (org.opentosca.container.api.dto.plan.PlanDTO)8 ApiOperation (io.swagger.annotations.ApiOperation)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 Api (io.swagger.annotations.Api)4 ApiParam (io.swagger.annotations.ApiParam)4 URI (java.net.URI)4 List (java.util.List)4 NotFoundException (javax.ws.rs.NotFoundException)4 PathParam (javax.ws.rs.PathParam)4 Context (javax.ws.rs.core.Context)4 Link (javax.ws.rs.core.Link)4 MediaType (javax.ws.rs.core.MediaType)4 Response (javax.ws.rs.core.Response)4 UriInfo (javax.ws.rs.core.UriInfo)4 TPlan (org.eclipse.winery.model.tosca.TPlan)4 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)4 UriUtil (org.opentosca.container.core.common.uri.UriUtil)4 Csar (org.opentosca.container.core.model.csar.Csar)4