private FinalStateManagedResource createWebsite(String protocol, FinalStateManagedResourcesUpdateEventHandlerContext<UrlRedirection> context, IPResourceService resourceService, String domainName,
List<Machine> machines) {
Website website = new Website(protocol + " Redirection of " + domainName);
FinalStateManagedResource websiteFinalResource = new FinalStateManagedResource();
websiteFinalResource.setManagedResource(website);
context.addManagedResources(websiteFinalResource);
website.getDomainNames().add(domainName);
website.setHttps("HTTPS".equals(protocol));
websiteFinalResource.addManagedLinksToType(LinkTypeConstants.POINTS_TO, LinkTypeConstants.INSTALLED_ON, LinkTypeConstants.USES);
machines.forEach(machine -> {
websiteFinalResource.addLinkTo(LinkTypeConstants.INSTALLED_ON, machine);
String applicationName = "infra_url_redirection_" + protocol.toLowerCase() + "-" + machine.getName().replaceAll("\\.", "_");
logger.info("Getting application {}", applicationName);
Optional<Application> application = resourceService.resourceFind(resourceService.createResourceQuery(Application.class)
.propertyEquals(Application.PROPERTY_NAME, applicationName)
);
if (!application.isPresent()) {
logger.info("Application {} does not exist for now. Skipping", applicationName);
return;
}
websiteFinalResource.addLinkTo(LinkTypeConstants.POINTS_TO, application.get());
});
return websiteFinalResource;
}