use of org.eclipse.winery.repository.splitting.Splitting in project winery by eclipse.
the class ServiceTemplateResource method injectNodeTemplates.
@POST
@Path("injector/replace")
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response injectNodeTemplates(InjectorReplaceData injectorReplaceData, @Context UriInfo uriInfo) throws Exception, IOException, ParserConfigurationException, SAXException, SplittingException {
if (injectorReplaceData.hostInjections != null) {
Collection<TTopologyTemplate> hostInjectorTopologyTemplates = injectorReplaceData.hostInjections.values();
hostInjectorTopologyTemplates.forEach(t -> {
try {
ModelUtilities.patchAnyAttributes(t.getNodeTemplates());
} catch (IOException e) {
LOGGER.error("XML was invalid", e);
}
});
}
if (injectorReplaceData.connectionInjections != null) {
Collection<TTopologyTemplate> connectionInjectorTopologyTemplates = injectorReplaceData.connectionInjections.values();
connectionInjectorTopologyTemplates.forEach(t -> {
try {
ModelUtilities.patchAnyAttributes(t.getNodeTemplates());
} catch (IOException e) {
LOGGER.error("XML was invalid", e);
}
});
}
Splitting splitting = new Splitting();
TTopologyTemplate matchedHostsTopologyTemplate;
TTopologyTemplate matchedConnectedTopologyTemplate;
// Test Method findOpenRequirements
Map<TRequirement, String> requirementsAndMatchingBasisCapabilityTypes = splitting.getOpenRequirementsAndMatchingBasisCapabilityTypeNames(this.getServiceTemplate().getTopologyTemplate());
// Output check
for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) {
System.out.println("open Requirement: " + req.getId());
System.out.println("matchingbasisType: " + requirementsAndMatchingBasisCapabilityTypes.get(req));
}
if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) {
matchedHostsTopologyTemplate = splitting.injectNodeTemplates(this.getServiceTemplate().getTopologyTemplate(), injectorReplaceData.hostInjections);
if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
matchedConnectedTopologyTemplate = splitting.injectConnectionNodeTemplates(matchedHostsTopologyTemplate, injectorReplaceData.connectionInjections);
} else {
matchedConnectedTopologyTemplate = matchedHostsTopologyTemplate;
}
} else if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
matchedConnectedTopologyTemplate = splitting.injectConnectionNodeTemplates(this.getServiceTemplate().getTopologyTemplate(), injectorReplaceData.connectionInjections);
} else {
throw new SplittingException("No open Requirements which can be matched");
}
TTopologyTemplate daSpecifiedTopology = matchedConnectedTopologyTemplate;
// Start additional functionality Driver Injection
if (!DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate).isEmpty() && DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate) != null) {
daSpecifiedTopology = DriverInjection.injectDriver(matchedConnectedTopologyTemplate);
}
// End additional functionality Driver Injection
this.getServiceTemplate().setTopologyTemplate(daSpecifiedTopology);
LOGGER.debug("Persisting...");
RestUtils.persist(this);
LOGGER.debug("Persisted.");
// No renaming of the Service Template allowed because of the plans
URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(id));
LOGGER.debug("URI of the old and new service template {}", url.toString());
return Response.created(url).build();
}
use of org.eclipse.winery.repository.splitting.Splitting in project winery by eclipse.
the class ServiceTemplateResource method getInjectorOptions.
@GET
@Path("injector/options")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response getInjectorOptions() {
Splitting splitting = new Splitting();
TTopologyTemplate topologyTemplate = this.getServiceTemplate().getTopologyTemplate();
Map<String, List<TTopologyTemplate>> hostMatchingOptions;
Map<String, List<TTopologyTemplate>> connectionMatchingOptions;
InjectorReplaceOptions injectionReplaceOptions = new InjectorReplaceOptions();
try {
Map<TRequirement, String> requirementsAndMatchingBasisCapabilityTypes = splitting.getOpenRequirementsAndMatchingBasisCapabilityTypeNames(this.getServiceTemplate().getTopologyTemplate());
// Output check
for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) {
System.out.println("open Requirement: " + req.getId());
System.out.println("matchingBasisType: " + requirementsAndMatchingBasisCapabilityTypes.get(req));
}
if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) {
hostMatchingOptions = splitting.getHostingMatchingOptionsWithDefaultLabeling(topologyTemplate);
} else {
hostMatchingOptions = null;
}
if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) {
connectionMatchingOptions = splitting.getConnectionInjectionOptions(topologyTemplate);
} else {
connectionMatchingOptions = null;
}
injectionReplaceOptions.setTopologyTemplate(topologyTemplate);
injectionReplaceOptions.setHostInjectionOptions(hostMatchingOptions);
injectionReplaceOptions.setConnectionInjectionOptions(connectionMatchingOptions);
if (hostMatchingOptions == null && connectionMatchingOptions == null) {
return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("No need for matching").build();
}
} catch (SplittingException e) {
LOGGER.error("Could not match", e);
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
}
return Response.ok().entity(injectionReplaceOptions).build();
}
use of org.eclipse.winery.repository.splitting.Splitting in project winery by eclipse.
the class TopologyTemplateResource method match.
@Path("match/")
@Produces(MediaType.TEXT_PLAIN)
@POST
public Response match(@Context UriInfo uriInfo) {
Splitting splitting = new Splitting();
ServiceTemplateId matchedServiceTemplateId;
try {
matchedServiceTemplateId = splitting.matchTopologyOfServiceTemplate((ServiceTemplateId) this.serviceTemplateRes.getId());
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Could not match. " + e.getMessage()).build();
}
URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(matchedServiceTemplateId));
return Response.created(url).build();
}
use of org.eclipse.winery.repository.splitting.Splitting in project winery by eclipse.
the class TopologyTemplateResource method split.
@Path("split/")
@Produces(MediaType.TEXT_PLAIN)
@POST
public Response split(@Context UriInfo uriInfo) {
Splitting splitting = new Splitting();
ServiceTemplateId splitServiceTemplateId;
try {
splitServiceTemplateId = splitting.splitTopologyOfServiceTemplate((ServiceTemplateId) this.serviceTemplateRes.getId());
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Could not split. " + e.getMessage()).build();
}
URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(splitServiceTemplateId));
return Response.created(url).build();
}
use of org.eclipse.winery.repository.splitting.Splitting in project winery by eclipse.
the class TopologyTemplateResource method composeServiceTemplates.
@POST
@Path("compose/")
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON })
public Response composeServiceTemplates(CompositionData compositionData, @Context UriInfo uriInfo) {
Splitting splitting = new Splitting();
String newComposedSolutionServiceTemplateId = compositionData.getTargetid();
List<ServiceTemplateId> compositionServiceTemplateIDs = new ArrayList<>();
compositionData.getCspath().stream().forEach(entry -> {
QName qName = QName.valueOf(entry);
compositionServiceTemplateIDs.add(new ServiceTemplateId(qName.getNamespaceURI(), qName.getLocalPart(), false));
});
ServiceTemplateId composedServiceTemplateId;
try {
composedServiceTemplateId = splitting.composeServiceTemplates(newComposedSolutionServiceTemplateId, compositionServiceTemplateIDs);
} catch (Exception e) {
e.printStackTrace();
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
}
Response mergeResponse = this.mergeWithOtherTopologyTemplate(composedServiceTemplateId.getQName().toString());
if (mergeResponse.getStatus() == 500) {
return mergeResponse;
}
URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(serviceTemplateRes.getId()));
String location = url.toString();
location = location + "topologytemplate?edit";
url = RestUtils.createURI(location);
LOGGER.debug("URI of the composed Service Template {}", url.toString());
return Response.created(url).build();
}
Aggregations