use of org.eclipse.winery.common.version.WineryVersion 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);
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class RestUtilsWithGitBackendTest method releaseComponentWhichDoesNotHaveChanges.
@Test
public void releaseComponentWhichDoesNotHaveChanges() throws Exception {
this.setRevisionTo("origin/plain");
DefinitionsChildId id = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2-wip1", false);
DefinitionsChildId releasedId = new NodeTypeId("http://opentosca.org/nodetypes", "NodeTypeWithALowerReleasableManagementVersion_2-w2", false);
int formerVersionCount = WineryVersionUtils.getAllVersionsOfOneDefinition(id, repository).size();
Response response = RestUtils.releaseVersion(id);
int finalVersionCount = WineryVersionUtils.getAllVersionsOfOneDefinition(releasedId, repository).size();
WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(releasedId, repository);
assertEquals(201, response.getStatus());
assertEquals(formerVersionCount + 1, finalVersionCount);
assertFalse(version.isReleasable());
assertEquals(0, version.getWorkInProgressVersion());
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class ServiceTemplateResourceTest method createNewStatefulVersion.
@Test
public void createNewStatefulVersion() throws Exception {
this.setRevisionTo("eb37f5cfec50c046985eac308e46482ce8bea8e3");
String response = this.assertPostWithNoContent("servicetemplates/http%253A%252F%252Fplain.winery.opentosca.org%252Fservicetemplates/ServiceTemplateWithOneNodeTemplate_w1-wip1/createnewstatefulversion", ContentType.JSON);
QNameApiData newId = JacksonProvider.mapper.readValue(response, QNameApiData.class);
assertNonNull(newId);
WineryVersion version = VersionUtils.getVersion(newId.localname);
assertNonNull(version);
assertTrue(version.getComponentVersion().startsWith("stateful-w1-wip1-"));
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class XmlRepository method getDefinitionsChildIds.
public <T extends DefinitionsChildId> SortedSet<T> getDefinitionsChildIds(Class<T> idClass, boolean omitDevelopmentVersions) {
SortedSet<T> res = new TreeSet<>();
String rootPathFragment = IdUtil.getRootPathFragment(idClass);
Path dir = makeAbsolute(Paths.get(rootPathFragment));
if (!Files.exists(dir)) {
// return empty list if no ids are available
return res;
}
assert (Files.isDirectory(dir));
final OnlyNonHiddenDirectories hiddenDirectories = new OnlyNonHiddenDirectories();
// list all directories contained in this directory
try (DirectoryStream<Path> ds = Files.newDirectoryStream(dir, hiddenDirectories)) {
for (Path nsP : ds) {
// the current path is the namespace
Namespace ns = new Namespace(nsP.getFileName().toString(), true);
try (DirectoryStream<Path> idDS = Files.newDirectoryStream(nsP, hiddenDirectories)) {
for (Path idP : idDS) {
XmlId xmlId = new XmlId(idP.getFileName().toString(), true);
if (omitDevelopmentVersions) {
WineryVersion version = VersionUtils.getVersion(xmlId.getDecoded());
if (version.toString().length() > 0 && version.getWorkInProgressVersion() > 0) {
continue;
}
}
Constructor<T> constructor;
try {
constructor = idClass.getConstructor(Namespace.class, XmlId.class);
} catch (Exception e) {
LOGGER.debug("Internal error at determining id constructor", e);
// abort everything, return invalid result
return res;
}
T id;
try {
id = constructor.newInstance(ns, xmlId);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
LOGGER.debug("Internal error at invocation of id constructor", e);
// abort everything, return invalid result
return res;
}
res.add(id);
}
}
}
} catch (IOException e) {
LOGGER.debug("Cannot close ds", e);
}
return res;
}
use of org.eclipse.winery.common.version.WineryVersion in project winery by eclipse.
the class VersionUtilsTest method getVersionFromNameWithMultipleUnderscores.
@Test
public void getVersionFromNameWithMultipleUnderscores() {
WineryVersion version = VersionUtils.getVersion("myExample_Component_v1.3.0-w1");
assertEquals("v1.3.0", version.getComponentVersion());
assertEquals(1, version.getWineryVersion());
assertEquals(0, version.getWorkInProgressVersion());
}
Aggregations