Skip to content

Commit

Permalink
Remove top node before adding new.
Browse files Browse the repository at this point in the history
Also includes name updates to keep supporting WAR-17 and 8
  • Loading branch information
KuhnMn committed Oct 23, 2023
1 parent 5cbec25 commit c1483c5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,49 @@ export async function serviceTemplateExists(serviceTemplateName) {
)}/${encodeURIComponent(encodeURIComponent(serviceTemplateName))}`,
{
method: "GET",
headers: {
Accept: "application/json",
},
}
);
return response.status === 200;
}

export async function deleteTagByID(serviceTemplateAddress, tagID) {
const response = await fetch(
`${getWineryEndpoint()}/servicetemplates/${serviceTemplateAddress}tags/${tagID}`,
{
method: "DELETE",
headers: {
Accept: "application/json",
},
}
);
return response.status === 204;
}

export async function getTags(serviceTemplateAddress) {
const response = await fetch(
`${getWineryEndpoint()}/servicetemplates/${serviceTemplateAddress}tags/`,
{
method: "GET",
headers: {
Accept: "application/json",
},
}
);
return response.json();
}

export async function deleteTopNodeTag(serviceTemplateAddress) {
const tags = await getTags(serviceTemplateAddress);
const topNodeTag = tags.find((tag) => tag.name === "top-node");
if (topNodeTag) {
return deleteTagByID(serviceTemplateAddress, topNodeTag.id);
}
return true;
}

export async function addNodeWithArtifactToServiceTemplateByName(
serviceTemplateName,
nodeTypeQName,
Expand Down Expand Up @@ -325,11 +363,11 @@ const nodeTypeQNameMapping = new Map([
"{http://opentosca.org/nodetypes}TomcatApplication_WAR-w1",
],
[
"{http://opentosca.org/artifacttypes}WAR17",
"{http://opentosca.org/artifacttypes}WAR-Java17",
"{http://opentosca.org/nodetypes}TomcatApplication_WAR-w1",
],
[
"{http://opentosca.org/artifacttypes}WAR8",
"{http://opentosca.org/artifacttypes}WAR-Java8",
"{http://opentosca.org/nodetypes}TomcatApplication_WAR-w1",
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
serviceTemplateExists,
addNodeWithArtifactToServiceTemplateByName,
deleteArtifactTemplate,
deleteTopNodeTag,
} from "../../deployment/WineryUtils";
import NotificationHandler from "../../../../editor/ui/notifications/NotificationHandler";
import { getWineryEndpoint } from "../../framework-config/config-manager";
Expand Down Expand Up @@ -105,6 +106,7 @@ export default function ArtifactUploadModal({
const nodeTypeQName = getNodeTypeQName(selectedOption);
const serviceTemplateName = `${namePrefix}ServiceTemplate-${element.id}`;
const doesExist = await serviceTemplateExists(serviceTemplateName);
console.log("doesExist", doesExist);
if (doesExist) {
serviceTemplateAddress =
await addNodeWithArtifactToServiceTemplateByName(
Expand All @@ -115,6 +117,7 @@ export default function ArtifactUploadModal({
`${namePrefix}Artifact-${element.id}`,
selectedOption
);
await deleteTopNodeTag(serviceTemplateAddress);
} else {
serviceTemplateAddress = await createServiceTemplateWithNodeAndArtifact(
serviceTemplateName,
Expand Down

0 comments on commit c1483c5

Please sign in to comment.