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());
}
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());
}
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;
}
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);
}
}
}
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();
}
Aggregations