Search in sources :

Example 1 with ArtifactTemplateResource

use of org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource in project winery by eclipse.

the class RestUtils method createArtifactTemplate.

public static ArtifactTemplateId createArtifactTemplate(InputStream uploadedInputStream, FormDataContentDisposition fileDetail, FormDataBodyPart body, QName artifactType, UriInfo uriInfo) {
    ArtifactTemplatesResource templateResource = new ArtifactTemplatesResource();
    QNameWithTypeApiData qNameApiData = new QNameWithTypeApiData();
    qNameApiData.localname = "xaasPackager_" + fileDetail.getFileName();
    qNameApiData.namespace = "http://opentosca.org/xaaspackager";
    qNameApiData.type = artifactType.toString();
    templateResource.onJsonPost(qNameApiData);
    ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId("http://opentosca.org/xaaspackager", "xaasPackager_" + fileDetail.getFileName(), false);
    ArtifactTemplateResource atRes = new ArtifactTemplateResource(artifactTemplateId);
    atRes.getFilesResource().onPost(uploadedInputStream, fileDetail, body, uriInfo);
    return artifactTemplateId;
}
Also used : QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource)

Example 2 with ArtifactTemplateResource

use of org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource in project winery by eclipse.

the class EdmmResource method createPlaceholders.

@POST
@Consumes(MediaType.TEXT_PLAIN)
@Path("create-placeholders-scripts")
public Response createPlaceholders(String componentType, @Context UriInfo uriInfo) throws IOException {
    // adding the interface to the component node type
    NodeTypeResource nodeTypeResource = new NodeTypesResource().getComponentInstanceResource(EncodingUtil.URLencode(NODE_TYPES), componentType);
    // the interfaces will be overridden
    nodeTypeResource.getInterfaces().onPost(buildInterfacesForNodeType(LIFECYCLE_NAME, LIFECYCLE));
    for (String operation : LIFECYCLE) {
        // adding a new artifact template
        final String artifactLocalName = componentType + "-" + StringUtils.capitalize(operation);
        ArtifactTemplatesResource artifactTemplatesResource = new ArtifactTemplatesResource();
        QNameWithTypeApiData qNameWithTypeApiData = new QNameWithTypeApiData(artifactLocalName, ARTIFACT_TEMPLATES, "{" + ARTIFACT_TYPES + "}Script");
        artifactTemplatesResource.onJsonPost(qNameWithTypeApiData);
        // adding the placeholder file
        ArtifactTemplateResource artifactTemplateResource = artifactTemplatesResource.getComponentInstanceResource(EncodingUtil.URLencode(ARTIFACT_TEMPLATES), artifactLocalName);
        boolean fileExists = artifactTemplateResource.getFilesResource().getAllFileMetas().stream().anyMatch(fileMeta -> fileMeta.getName().equals(operation + ".sh"));
        // if the file exists it will be overridden, but we do not want that.
        if (!fileExists) {
            artifactTemplateResource.getFilesResource().putContentToFile(operation + ".sh", getPlaceholderFile(operation), "text/x-sh");
            artifactTemplateResource.synchronizeReferences();
        }
        // creating a new node type implementation
        String nodeTypeImplementationLocalName = componentType + "-IA";
        NodeTypeImplementationsResource nodeTypeImplementationsResource = new NodeTypeImplementationsResource();
        qNameWithTypeApiData = new QNameWithTypeApiData(nodeTypeImplementationLocalName, NODE_TYPE_IMPLEMENTATIONS, "{" + NODE_TYPES + "}" + componentType);
        nodeTypeImplementationsResource.onJsonPost(qNameWithTypeApiData);
        // linking the artifact template to the node type implementation
        NodeTypeImplementationResource nodeTypeImplementationResource = nodeTypeImplementationsResource.getComponentInstanceResource(EncodingUtil.URLencode(NODE_TYPE_IMPLEMENTATIONS), nodeTypeImplementationLocalName);
        GenerateArtifactApiData artifactApiData = new GenerateArtifactApiData();
        artifactApiData.artifactName = operation;
        artifactApiData.artifactTemplate = "{" + ARTIFACT_TEMPLATES + "}" + artifactLocalName;
        artifactApiData.interfaceName = LIFECYCLE_NAME;
        artifactApiData.operationName = operation;
        boolean implementationResourceExists = nodeTypeImplementationResource.getImplementationArtifacts().getAllArtifactResources().stream().anyMatch(artifactResource -> {
            TImplementationArtifact implementationArtifact = artifactResource.getImplementationArtifact();
            return operation.equals(implementationArtifact.getOperationName()) && LIFECYCLE_NAME.equals(implementationArtifact.getInterfaceName()) && implementationArtifact.getArtifactRef() != null && artifactApiData.artifactTemplate.equals(implementationArtifact.getArtifactRef().toString());
        });
        if (!implementationResourceExists) {
            nodeTypeImplementationResource.getImplementationArtifacts().generateArtifact(artifactApiData, uriInfo);
        }
    }
    return Response.status(Response.Status.CREATED).build();
}
Also used : TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) NodeTypeImplementationsResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationsResource) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) NodeTypeResource(org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypeResource) NodeTypeImplementationResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationResource) GenerateArtifactApiData(org.eclipse.winery.repository.rest.resources.apiData.GenerateArtifactApiData) NodeTypesResource(org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.NodeTypesResource) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 3 with ArtifactTemplateResource

use of org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource in project winery by eclipse.

the class NodeTemplateResource method createStateElement.

@POST
@Path("state")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createStateElement(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body, @Context UriInfo uriInfo) {
    LOGGER.debug("Received state artifact for Node Template {} with ID {}", this.nodeTemplate.getName(), this.nodeTemplate.getId());
    LOGGER.debug("Artifact file name is {} and is {} bytes big.", fileDetail.getFileName(), fileDetail.getSize());
    // ensure that the artifact type exists.
    IRepository repo = RepositoryFactory.getRepository();
    repo.getElement(new ArtifactTypeId(OpenToscaBaseTypes.stateArtifactType));
    // create DA
    Optional<TDeploymentArtifact> stateDeploymentArtifact = this.getDeploymentArtifacts().getDeploymentArtifacts().stream().filter(artifact -> artifact.getArtifactType() != null).filter(artifact -> artifact.getArtifactType().equals(OpenToscaBaseTypes.stateArtifactType)).findFirst();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
    TDeploymentArtifact deploymentArtifact = new TDeploymentArtifact.Builder("state", OpenToscaBaseTypes.stateArtifactType).build();
    String componentVersion = dateFormat.format(new Date());
    ArtifactTemplateId newArtifactTemplateId = new ArtifactTemplateId("http://opentosca.org/artifacttemplates", this.getServiceTemplateResource().getServiceTemplate().getName() + "-" + this.nodeTemplate.getId() + "-State" + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + componentVersion + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1", false);
    LOGGER.debug("Created Artifact Template of Type \"State\" called {}", newArtifactTemplateId.getQName());
    // if there is already a state artifact, update the file
    if (stateDeploymentArtifact.isPresent()) {
        LOGGER.debug("Updating the state DA of the Node Template...");
        deploymentArtifact = stateDeploymentArtifact.get();
        // create new ArtifactTemplate version
        ArtifactTemplateId oldArtifactTemplateId = new ArtifactTemplateId(deploymentArtifact.getArtifactRef());
        List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(oldArtifactTemplateId, repo);
        WineryVersion newWineryVersion = VersionUtils.getNewWineryVersion(versions);
        newWineryVersion.setWorkInProgressVersion(0);
        newWineryVersion.setComponentVersion(componentVersion);
        newArtifactTemplateId = (ArtifactTemplateId) VersionSupport.getDefinitionInTheGivenVersion(oldArtifactTemplateId, newWineryVersion);
    } else {
        LOGGER.debug("Creating the state DA of the Node Template...");
        List<TDeploymentArtifact> list = this.nodeTemplate.getDeploymentArtifacts();
        if (Objects.isNull(list)) {
            list = new ArrayList<>();
            this.nodeTemplate.setDeploymentArtifacts(list);
        }
        list.add(deploymentArtifact);
    }
    new ArtifactTemplatesResource().onJsonPost(new QNameWithTypeApiData(newArtifactTemplateId.getQName().getLocalPart(), newArtifactTemplateId.getQName().getNamespaceURI(), OpenToscaBaseTypes.stateArtifactType.toString()));
    LOGGER.debug("Attaching the new Artifact...");
    deploymentArtifact.setArtifactRef(newArtifactTemplateId.getQName());
    Response response = new ArtifactTemplateResource(newArtifactTemplateId).getFilesResource().onPost(uploadedInputStream, fileDetail, body, uriInfo, this.nodeTemplate.getId() + ".state");
    if (response.getStatus() != Response.Status.CREATED.getStatusCode()) {
        LOGGER.debug("Could not create artifact file! Response was {}", response);
        return response;
    }
    LOGGER.debug("Persisting now...");
    return RestUtils.persist(this.res);
}
Also used : Produces(javax.ws.rs.Produces) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Date(java.util.Date) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) Namespace(org.eclipse.winery.model.ids.Namespace) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) OpenToscaBaseTypes(org.eclipse.winery.model.tosca.constants.OpenToscaBaseTypes) WineryVersion(org.eclipse.winery.common.version.WineryVersion) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) IdNames(org.eclipse.winery.model.ids.IdNames) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) Namespaces(org.eclipse.winery.model.tosca.constants.Namespaces) VersionSupport(org.eclipse.winery.model.version.VersionSupport) IPersistable(org.eclipse.winery.repository.rest.resources._support.IPersistable) Map(java.util.Map) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) TEntityTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.TEntityTemplateResource) WineryVersionUtils(org.eclipse.winery.repository.backend.WineryVersionUtils) IIdDetermination(org.eclipse.winery.repository.rest.resources._support.collections.IIdDetermination) Context(javax.ws.rs.core.Context) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) DeploymentArtifactsResource(org.eclipse.winery.repository.rest.resources.artifacts.DeploymentArtifactsResource) Objects(java.util.Objects) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) List(java.util.List) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) Response(javax.ws.rs.core.Response) VersionUtils(org.eclipse.winery.common.version.VersionUtils) IRepository(org.eclipse.winery.repository.backend.IRepository) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) Optional(java.util.Optional) RestUtils(org.eclipse.winery.repository.rest.RestUtils) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) GenericDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.GenericDirectoryId) HEAD(javax.ws.rs.HEAD) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) GenericFileResource(org.eclipse.winery.repository.rest.resources._support.GenericFileResource) SimpleDateFormat(java.text.SimpleDateFormat) ArrayList(java.util.ArrayList) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) FormParam(javax.ws.rs.FormParam) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) INodeTemplateResourceOrNodeTypeImplementationResource(org.eclipse.winery.repository.rest.resources._support.INodeTemplateResourceOrNodeTypeImplementationResource) PUT(javax.ws.rs.PUT) InputStream(java.io.InputStream) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) Date(java.util.Date) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) Response(javax.ws.rs.core.Response) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) IRepository(org.eclipse.winery.repository.backend.IRepository) SimpleDateFormat(java.text.SimpleDateFormat) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Aggregations

Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)2 QNameWithTypeApiData (org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData)2 ArtifactTemplateResource (org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource)2 ArtifactTemplatesResource (org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource)2 ApiOperation (io.swagger.annotations.ApiOperation)1 InputStream (java.io.InputStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 FormParam (javax.ws.rs.FormParam)1 GET (javax.ws.rs.GET)1 HEAD (javax.ws.rs.HEAD)1 PUT (javax.ws.rs.PUT)1