public void resourceRefresh(Long resourceId) { if (resourceId == null) { throw new IllegalUpdateException("Cannot delete a resource without id"); } if (!resourcesToRefresh.contains(resourceId)) { resourcesToRefresh.add(resourceId); } }
private void validate(MariaDBDatabase resource) { if (blacklisted.contains(resource.getName().toLowerCase())) { throw new IllegalUpdateException("That database name is blacklisted"); } }
private void validate(MariaDBUser resource) { if (blacklisted.contains(resource.getName().toLowerCase())) { throw new IllegalUpdateException("That user name is blacklisted"); } }
public void resourceUpdate(Long resourceId, IPResource updatedResource) { if (resourceId == null) { throw new IllegalUpdateException("Cannot modify a resource without id"); } // Remove previous update resourcesToUpdate.removeIf(it -> it.getA() == resourceId); resourcesToDelete.removeIf(it -> it == resourceId); resourcesToRefresh.removeIf(it -> it == resourceId); resourcesToUpdate.add(new Tuple2<>(resourceId, updatedResource)); }
throw new IllegalUpdateException("Can only use a single certificate"); throw new IllegalUpdateException("Can only use a single database server"); throw new IllegalUpdateException("Can only use a single database"); throw new IllegalUpdateException("Can only use a single database user"); throw new IllegalUpdateException("Can only use a single unix user"); MariaDBUser mariaDBUser = mariaDBUsers.get(0); if (!resourceService.linkExistsByFromResourceAndLinkTypeAndToResource(mariaDBDatabase, LinkTypeConstants.INSTALLED_ON, mariaDBServer)) { throw new IllegalUpdateException("The database is not installed on the database server"); throw new IllegalUpdateException("The database user is not an ADMIN on the database"); throw new IllegalUpdateException("The database user is not a READER on the database"); throw new IllegalUpdateException("The database user is not a WRITER on the database");
throw new IllegalUpdateException("Can only use a single certificate"); throw new IllegalUpdateException("Can only use a single database server"); throw new IllegalUpdateException("Can only use a single database"); throw new IllegalUpdateException("Can only use a single database user"); throw new IllegalUpdateException("Can only use a single unix user"); MariaDBUser mariaDBUser = mariaDBUsers.get(0); if (!resourceService.linkExistsByFromResourceAndLinkTypeAndToResource(mariaDBDatabase, LinkTypeConstants.INSTALLED_ON, mariaDBServer)) { throw new IllegalUpdateException("The database is not installed on the database server"); throw new IllegalUpdateException("The database user is not an ADMIN on the database"); throw new IllegalUpdateException("The database user is not a READER on the database"); throw new IllegalUpdateException("The database user is not a WRITER on the database");
public void resourceDelete(Long resourceId) { if (resourceId == null) { throw new IllegalUpdateException("Cannot delete a resource without id"); } resourcesToDelete.add(resourceId); // Remove in add and update Optional<IPResource> resourceOptional = resourceService.resourceFind(resourceId); if (resourceOptional.isPresent()) { IPResource resource = resourceOptional.get(); resourcesToAdd.removeIf(it -> resourceService.resourceEqualsPk(resource, it)); } resourcesToUpdate.removeIf(it -> it.getA() == resourceId); }
private void checkUniqueName(CommonServicesContext services, String name) { IPResourceService resourceService = services.getResourceService(); List<UnixUser> unixUsers = resourceService.resourceFindAll(resourceService.createResourceQuery(UnixUser.class) // .propertyEquals(UnixUser.PROPERTY_NAME, name)); if (unixUsers.size() > 1) { throw new IllegalUpdateException("Unix User name " + name + " is already used"); } }
private void checkUniqueName(CommonServicesContext services, String name) { IPResourceService resourceService = services.getResourceService(); List<UnixUser> unixUsers = resourceService.resourceFindAll(resourceService.createResourceQuery(UnixUser.class) // .propertyEquals(UnixUser.PROPERTY_NAME, name)); if (unixUsers.size() > 1) { throw new IllegalUpdateException("Unix User name " + name + " is already used"); } }
@Override protected void commonHandlerExecute(CommonServicesContext services, ChangesContext changes, CommonMethodUpdateEventHandlerContext<EmailDomain> context) { EmailDomain emailDomain = context.getResource(); // Ensure all account names are unique per account and per redirection (can be shared) Set<String> accountNames = new HashSet<>(); services.getResourceService().linkFindAllByFromResourceClassAndLinkTypeAndToResource(EmailAccount.class, LinkTypeConstants.INSTALLED_ON, emailDomain).forEach(account -> { if (!accountNames.add(account.getAccountName())) { throw new IllegalUpdateException("The email account [" + account.getAccountName() + "@" + emailDomain.getDomainName() + "] exists multiple times"); } }); accountNames.clear(); services.getResourceService().linkFindAllByFromResourceClassAndLinkTypeAndToResource(EmailRedirection.class, LinkTypeConstants.INSTALLED_ON, emailDomain).forEach(redirection -> { if (!accountNames.add(redirection.getAccountName())) { throw new IllegalUpdateException("The email redirection [" + redirection.getAccountName() + "@" + emailDomain.getDomainName() + "] exists multiple times"); } }); // Ensure only linked to one EmailServer if (services.getResourceService().linkFindAllByFromResourceAndLinkTypeAndToResourceClass(emailDomain, LinkTypeConstants.INSTALLED_ON, EmailServer.class).size() > 1) { throw new IllegalUpdateException("The email domain [" + emailDomain.getDomainName() + "] is installed on more than one Email server"); } }
static protected void validate(CommonServicesContext services, DnsEntry dnsEntry) { if (!Strings.isNullOrEmpty(dnsEntry.getName())) { if (typesWithDomain.contains(dnsEntry.getType()) && !DomainValidator.getInstance().isValid(dnsEntry.getName())) { throw new IllegalUpdateException(services.getTranslationService().translate("error.notADomainName")); } if (strictTypesWithDomain.contains(dnsEntry.getType()) && !startWithLetterValidationRegex.matcher(dnsEntry.getName()).matches()) { throw new IllegalUpdateException(services.getTranslationService().translate("error.notStartingWithLetter")); } if (dnsEntry.getType() == DnsEntryType.A && !validIp(dnsEntry.getDetails())) { throw new IllegalUpdateException(services.getTranslationService().translate("error.notAnIp")); } if (dnsEntry.getName().contains(" ")) { throw new IllegalUpdateException(services.getTranslationService().translate("error.notADomainName")); } } }
static protected void validate(CommonServicesContext services, DnsEntry dnsEntry) { if (!Strings.isNullOrEmpty(dnsEntry.getName())) { if (typesWithDomain.contains(dnsEntry.getType()) && !DomainValidator.getInstance().isValid(dnsEntry.getName())) { throw new IllegalUpdateException(services.getTranslationService().translate("error.notADomainName")); } if (strictTypesWithDomain.contains(dnsEntry.getType()) && !startWithLetterValidationRegex.matcher(dnsEntry.getName()).matches()) { throw new IllegalUpdateException(services.getTranslationService().translate("error.notStartingWithLetter")); } if (dnsEntry.getType() == DnsEntryType.A && !validIp(dnsEntry.getDetails())) { throw new IllegalUpdateException(services.getTranslationService().translate("error.notAnIp")); } if (dnsEntry.getName().contains(" ")) { throw new IllegalUpdateException(services.getTranslationService().translate("error.notADomainName")); } } }
@Override public void attachTo(AttachablePartContext context) { // Command IPApplicationDefinitionService service = new IPApplicationDefinitionService(name, command); service.setWorkingDirectory(workingDirectory); // Unix user List<UnixUser> unixUsers = context.getServices().getResourceService().linkFindAllByFromResourceAndLinkTypeAndToResourceClass(this, LinkTypeConstants.RUN_AS, UnixUser.class); if (unixUsers.size() > 1) { throw new IllegalUpdateException("Must have a singe unix user to run as. Got " + unixUsers.size()); } if (!unixUsers.isEmpty()) { service.setRunAs(unixUsers.get(0).getId()); } context.getApplicationDefinition().getServices().add(service); }
@Override public void attachTo(AttachablePartContext context) { // Get the MongoDBServer (fail if more than one) CommonServicesContext services = context.getServices(); List<MongoDBServer> servers = services.getResourceService().linkFindAllByFromResourceAndLinkTypeAndToResourceClass(this, LinkTypeConstants.POINTS_TO, MongoDBServer.class); if (servers.size() > 1) { throw new IllegalUpdateException("There cannot be more than 1 MongoDB Server. Has " + servers.size()); } if (servers.isEmpty()) { return; } MongoDBServer server = servers.get(0); // Get the Machines on the MongoDBServer List<Machine> machines = services.getResourceService().linkFindAllByFromResourceAndLinkTypeAndToResourceClass(server, LinkTypeConstants.INSTALLED_ON, Machine.class); if (machines.isEmpty()) { return; } // Add the infra on the Application Machine machine = machines.get(0); context.getApplicationDefinition().addPortRedirect(localPort, machine.getName(), server.getName(), "MONGODB_TCP"); }
@Override public void attachTo(AttachablePartContext context) { // Get the PostgreSqlServer (fail if more than one) CommonServicesContext services = context.getServices(); List<PostgreSqlServer> servers = services.getResourceService().linkFindAllByFromResourceAndLinkTypeAndToResourceClass(this, LinkTypeConstants.POINTS_TO, PostgreSqlServer.class); if (servers.size() > 1) { throw new IllegalUpdateException("There cannot be more than 1 PostgreSql Server. Has " + servers.size()); } if (servers.isEmpty()) { return; } PostgreSqlServer server = servers.get(0); // Get the Machines on the PostgreSqlServer List<Machine> machines = services.getResourceService().linkFindAllByFromResourceAndLinkTypeAndToResourceClass(server, LinkTypeConstants.INSTALLED_ON, Machine.class); if (machines.isEmpty()) { return; } // Add the infra on the Application Machine machine = machines.get(0); context.getApplicationDefinition().addPortRedirect(localPort, machine.getName(), server.getName(), "POSTGRESQL_TCP"); }
@Override public void attachTo(AttachablePartContext context) { // Get the MariaDBServer (fail if more than one) CommonServicesContext services = context.getServices(); List<MariaDBServer> servers = services.getResourceService().linkFindAllByFromResourceAndLinkTypeAndToResourceClass(this, LinkTypeConstants.POINTS_TO, MariaDBServer.class); if (servers.size() > 1) { throw new IllegalUpdateException("There cannot be more than 1 MariaDB Server. Has " + servers.size()); } if (servers.isEmpty()) { return; } MariaDBServer server = servers.get(0); // Get the Machines on the MariaDBServer List<Machine> machines = services.getResourceService().linkFindAllByFromResourceAndLinkTypeAndToResourceClass(server, LinkTypeConstants.INSTALLED_ON, Machine.class); if (machines.isEmpty()) { return; } // Add the infra on the Application Machine machine = machines.get(0); context.getApplicationDefinition().addPortRedirect(localPort, machine.getName(), server.getName(), DockerContainerEndpoints.MYSQL_TCP); }
throw new IllegalUpdateException("An application cannot have multiple users to run as (only 0 or 1)"); for (Integer port : application.getApplicationDefinition().getPortsExposed().keySet()) { if (!endpointPorts.add(port)) { throw new IllegalUpdateException("The port " + port + " is exposed by many applications installed on " + installedOnMachine.getName());
throw new IllegalUpdateException("An application cannot have multiple users to run as (only 0 or 1)"); for (Integer port : application.getApplicationDefinition().getPortsExposed().keySet()) { if (!endpointPorts.add(port)) { throw new IllegalUpdateException("The port " + port + " is exposed by many applications installed on " + installedOnMachine.getName());
@Override protected void commonHandlerExecute(CommonServicesContext services, ChangesContext changes, CommonMethodUpdateEventHandlerContext<Machine> context) { Machine resource = context.getResource(); if (context.getOldResource() != null && !StringTools.safeEquals(context.getOldResource().getName(), resource.getName())) { throw new IllegalUpdateException("You cannot change a Machine's name"); } context.getManagedResourceTypes().add(DnsEntry.class); if (resource.getPublicIp() != null) { // Use a DnsEntry context.getManagedResources().add(new DnsEntry(resource.getName(), DnsEntryType.A, resource.getPublicIp())); } }
@Override protected void commonHandlerExecute(CommonServicesContext services, ChangesContext changes, CommonMethodUpdateEventHandlerContext<Machine> context) { Machine resource = context.getResource(); if (context.getOldResource() != null && !StringTools.safeEquals(context.getOldResource().getName(), resource.getName())) { throw new IllegalUpdateException("You cannot change a Machine's name"); } context.getManagedResourceTypes().add(DnsEntry.class); if (resource.getPublicIp() != null) { // Use a DnsEntry context.getManagedResources().add(new DnsEntry(resource.getName(), DnsEntryType.A, resource.getPublicIp())); } }