Search in sources :

Example 21 with WineryVersion

use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.

the class RestUtilsWithGitBackendTest method getFlagsOfAReleasedVersion.

@Test
public void getFlagsOfAReleasedVersion() throws Exception {
    this.setRevisionTo("origin/plain");
    DefinitionsChildId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWith5Versions_0.3.4-w3", false);
    WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(id, repository);
    assertFalse(version.isReleasable());
    assertFalse(version.isEditable());
    assertTrue(version.isCurrentVersion());
    assertTrue(version.isLatestVersion());
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Example 22 with WineryVersion

use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.

the class RestUtilsWithGitBackendTest method getFlagsOfAReleasableVersion.

@Test
public void getFlagsOfAReleasableVersion() throws Exception {
    this.setRevisionTo("d920a1a37e3e1c3be32bf282a4d240d83811fdb1");
    DefinitionsChildId id = new NodeTypeId("http://plain.winery.opentosca.org/nodetypes", "NodeTypeWithImplementation_1.0-w1-wip1", false);
    WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(id, repository);
    assertTrue(version.isReleasable());
    assertTrue(version.isCurrentVersion());
    assertTrue(version.isLatestVersion());
    assertFalse(version.isEditable());
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Example 23 with WineryVersion

use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.

the class WineryVersionUtils method getVersionsList.

/**
 * @param current returns the current version in element [0] of this variable. Has to be non-null.
 * @return a list of available versions
 */
private static List<WineryVersion> getVersionsList(DefinitionsChildId id, final WineryVersion[] current, IRepository repository) {
    List<WineryVersion> versionList = getOtherVersionDefinitionsFromDefinition(id, repository).stream().map(element -> {
        WineryVersion version = VersionUtils.getVersionWithCurrentFlag(element.getXmlId().getDecoded(), id.getXmlId().getDecoded());
        if (version.isCurrentVersion()) {
            current[0] = version;
        }
        return version;
    }).sorted(Comparator.reverseOrder()).collect(Collectors.toList());
    // explicitly set the latest version and releasable flag
    versionList.get(0).setLatestVersion(true);
    versionList.get(0).setReleasable(true);
    boolean changesInFile = false;
    if (current[0].isVersionedInWinery() && repository instanceof MultiRepository) {
        for (IRepository inner : ((MultiRepository) repository).getRepositories()) {
            // notably not instanceof because possible subclasses of GitRepository may need separate handling
            if (inner.getClass().equals(GitBasedRepository.class)) {
                GitBasedRepository gitRepo = (GitBasedRepository) inner;
                if (gitRepo.hasChangesInFile(id)) {
                    changesInFile = true;
                }
            }
        }
    }
    if (repository.hasChangesInFile(id)) {
        changesInFile = true;
    }
    if (!current[0].isVersionedInWinery()) {
        changesInFile = true;
    }
    if (!current[0].isLatestVersion()) {
        // The current version may still be releasable, if it's the latest WIP version of a component version.
        List<WineryVersion> collect = versionList.stream().filter(version -> version.getComponentVersion().equals(current[0].getComponentVersion())).sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        current[0].setReleasable(collect.get(0).isCurrentVersion());
        // And if there are changes, it's also editable.
        current[0].setEditable(changesInFile && current[0].isReleasable());
    } else {
        current[0].setEditable(changesInFile);
    }
    // In RADON, all versions should always be editable
    if (Environments.isFeatureEnabled("radon")) {
        versionList.forEach(v -> v.setEditable(true));
    }
    return versionList;
}
Also used : MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) WineryVersion(org.eclipse.winery.common.version.WineryVersion)

Example 24 with WineryVersion

use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.

the class UbuntuVMPlugin method downloadDependenciesBasedOnNodeType.

@Override
public void downloadDependenciesBasedOnNodeType(TNodeTypeImplementation nodeTypeImplementation, IRepository repository) {
    QName nodeType = nodeTypeImplementation.getNodeType();
    WineryVersion nodeTypeVersion = VersionUtils.getVersion(nodeType.getLocalPart());
    String componentVersion = nodeTypeVersion.getComponentVersion();
    if (componentVersion != null) {
        String codeName = getCodeName(componentVersion);
        if (codeName != null) {
            logger.info("Found code name '{}' for Ubuntu Node Type {}", codeName, nodeType);
            String nameWithoutVersion = VersionUtils.getNameWithoutVersion(nodeType.getLocalPart());
            WineryVersion artifactVersion = new WineryVersion(nodeTypeVersion.getComponentVersion() + "-CloudImage", 1, 1);
            ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId(OpenToscaBaseTypes.artifactTemplateNamespace, nameWithoutVersion + "-DA" + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + artifactVersion, false);
            TArtifactTemplate element = repository.getElement(artifactTemplateId);
            element.setType(OpenToscaBaseTypes.cloudImageArtifactType);
            logger.info("Generated ArtifactTemplate {}", artifactTemplateId.getQName());
            if (!repository.exists(artifactTemplateId)) {
                logger.info("Trying to download image file...");
                String baseUrl = "https://cloud-images.ubuntu.com/" + codeName + "/current/" + codeName + "-server-cloudimg-amd64";
                try {
                    URL url = new URL(baseUrl + imageFileType);
                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                    connection.setRequestMethod("HEAD");
                    int responseCode = connection.getResponseCode();
                    if (responseCode != 200) {
                        connection.disconnect();
                        logger.info("Image not found, trying with '-disk' suffix...");
                        url = new URL(baseUrl + imageDiskType);
                        connection = (HttpURLConnection) url.openConnection();
                        connection.setRequestMethod("HEAD");
                        responseCode = connection.getResponseCode();
                    }
                    if (responseCode == 200) {
                        repository.setElement(artifactTemplateId, element);
                        ArtifactTemplateFilesDirectoryId filesId = new ArtifactTemplateFilesDirectoryId(artifactTemplateId);
                        String fileName = url.getFile().substring(url.getFile().lastIndexOf("/") + 1);
                        RepositoryFileReference repositoryFileReference = new RepositoryFileReference(filesId, fileName);
                        try (InputStream inputStream = url.openStream()) {
                            repository.putContentToFile(repositoryFileReference, inputStream, MediaType.parse("application/x-image"));
                        }
                        BackendUtils.synchronizeReferences(repository, artifactTemplateId);
                        TDeploymentArtifact imageDa = new TDeploymentArtifact.Builder("CloudImage", OpenToscaBaseTypes.cloudImageArtifactType).setArtifactRef(artifactTemplateId.getQName()).build();
                        List<TDeploymentArtifact> deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
                        if (deploymentArtifacts == null) {
                            deploymentArtifacts = new ArrayList<>();
                            nodeTypeImplementation.setDeploymentArtifacts(deploymentArtifacts);
                        }
                        deploymentArtifacts.add(imageDa);
                    } else {
                        logger.info("Could not download image -- the URLs do not exist: \n\t{}\n\t{}", baseUrl + imageFileType, baseUrl + imageDiskType);
                    }
                } catch (IOException e) {
                    logger.info("Error while downloading image file!", e);
                }
            }
        } else {
            logger.info("Could not identify code name of given Ubuntu Node Type! {}", nodeType);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) InputStream(java.io.InputStream) IOException(java.io.IOException) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) URL(java.net.URL) ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) HttpURLConnection(java.net.HttpURLConnection) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) WineryVersion(org.eclipse.winery.common.version.WineryVersion)

Example 25 with WineryVersion

use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.

the class ServiceTemplateResource method createPlaceholderSubstituteVersion.

@Path("placeholdersubstitution")
@POST()
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createPlaceholderSubstituteVersion() throws IOException, SplittingException {
    TTopologyTemplate originTopologyTemplate = this.getServiceTemplate().getTopologyTemplate();
    if (originTopologyTemplate == null) {
        return Response.notModified().build();
    }
    List<TTag> tagsOfServiceTemplate = this.getServiceTemplate().getTags();
    List<OTParticipant> participants = originTopologyTemplate.getParticipants();
    String participantId = "";
    List<TTag> newTagList = new ArrayList<>();
    for (TTag tagOfServiceTemplate : tagsOfServiceTemplate) {
        if (tagOfServiceTemplate.getName().equals("participant")) {
            participantId = tagOfServiceTemplate.getValue();
            newTagList.add(tagOfServiceTemplate);
        } else if (!tagOfServiceTemplate.getName().equals("choreography")) {
            newTagList.add(tagOfServiceTemplate);
        }
    }
    final String finalParticipantId = participantId;
    List<String> nodeTemplatesWithNewHost = new ArrayList<>();
    for (TNodeTemplate tNodeTemplate : originTopologyTemplate.getNodeTemplates()) {
        // Multiple participants can be annotated on one node template
        Optional<String> nodeOwners = ModelUtilities.getParticipant(tNodeTemplate);
        if (nodeOwners.isPresent() && nodeOwners.get().contains(finalParticipantId)) {
            for (TRelationshipTemplate tRelationshipTemplate : ModelUtilities.getIncomingRelationshipTemplates(originTopologyTemplate, tNodeTemplate)) {
                nodeTemplatesWithNewHost.add(ModelUtilities.getSourceNodeTemplateOfRelationshipTemplate(originTopologyTemplate, tRelationshipTemplate).getId());
            }
        }
    }
    ServiceTemplateId id = (ServiceTemplateId) this.getId();
    WineryVersion version = VersionUtils.getVersion(id.getXmlId().getDecoded());
    WineryVersion newVersion = new WineryVersion("_substituted_" + version.toString(), 1, 1);
    ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionUtils.getNameWithoutVersion(id.getXmlId().getDecoded()) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersion.toString(), false);
    IRepository repo = RepositoryFactory.getRepository();
    if (repo.exists(newId)) {
        repo.forceDelete(newId);
    }
    ResourceResult response = RestUtils.duplicate(id, newId);
    TServiceTemplate newServiceTemplate = repo.getElement(newId);
    newServiceTemplate.setTopologyTemplate(BackendUtils.clone(originTopologyTemplate));
    newServiceTemplate.getTopologyTemplate().setParticipants(participants);
    Splitting splitting = new Splitting();
    Map<String, List<TTopologyTemplate>> resultList = splitting.getHostingInjectionOptions(BackendUtils.clone(newServiceTemplate.getTopologyTemplate()));
    for (Map.Entry<String, List<TTopologyTemplate>> entry : resultList.entrySet()) {
        Optional<String> nodeOwners = ModelUtilities.getParticipant(newServiceTemplate.getTopologyTemplate().getNodeTemplate(entry.getKey()));
        if (nodeOwners.isPresent() && nodeOwners.get().contains(finalParticipantId)) {
            if (nodeTemplatesWithNewHost.contains(entry.getKey()) && !resultList.get(entry.getKey()).isEmpty()) {
                Map<String, TTopologyTemplate> choiceTopologyTemplate = new LinkedHashMap<>();
                choiceTopologyTemplate.put(entry.getKey(), entry.getValue().get(0));
                splitting.injectNodeTemplates(newServiceTemplate.getTopologyTemplate(), choiceTopologyTemplate, InjectRemoval.REMOVE_REPLACED);
                for (TNodeTemplate injectNodeTemplate : choiceTopologyTemplate.get(entry.getKey()).getNodeTemplates()) {
                    injectNodeTemplate.getOtherAttributes().put(QNAME_PARTICIPANT, finalParticipantId);
                }
            }
        }
    }
    String choreoValue = splitting.calculateChoreographyTag(newServiceTemplate.getTopologyTemplate().getNodeTemplates(), participantId);
    TTag choreoTag = new TTag();
    choreoTag.setName("choreography");
    choreoTag.setValue(choreoValue);
    newTagList.add(choreoTag);
    newServiceTemplate.setTags(newTagList);
    repo.setElement(newId, newServiceTemplate);
    if (response.getStatus() == Status.CREATED) {
        response.setUri(null);
        response.setMessage(new QNameApiData(newId));
    }
    return response.getResponse();
}
Also used : TTag(org.eclipse.winery.model.tosca.TTag) QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) OTParticipant(org.eclipse.winery.model.tosca.extensions.OTParticipant) LinkedHashMap(java.util.LinkedHashMap) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) Splitting(org.eclipse.winery.repository.splitting.Splitting) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) List(java.util.List) ArrayList(java.util.ArrayList) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) WineryVersion(org.eclipse.winery.common.version.WineryVersion) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

WineryVersion (org.eclipse.winery.common.version.WineryVersion)37 Test (org.junit.jupiter.api.Test)19 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)14 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)12 Produces (javax.ws.rs.Produces)8 IRepository (org.eclipse.winery.repository.backend.IRepository)8 IOException (java.io.IOException)7 POST (javax.ws.rs.POST)7 Path (javax.ws.rs.Path)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 QName (javax.xml.namespace.QName)6 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)6 ResourceResult (org.eclipse.winery.repository.rest.resources._support.ResourceResult)6 QNameApiData (org.eclipse.winery.repository.rest.resources.apiData.QNameApiData)6 LinkedHashMap (java.util.LinkedHashMap)5 Response (javax.ws.rs.core.Response)5 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)4