use of org.eclipse.winery.repository.splitting.SplittingException 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.SplittingException 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();
}
Aggregations