public void resourceRefresh(Long resourceId) { if (resourceId == null) { throw new IllegalUpdateException("Cannot delete a resource without id"); } if (!resourcesToRefresh.contains(resourceId)) { resourcesToRefresh.add(resourceId); } }
public static long getNextAvailableId() { if (cachedSearchingAvailability == null) { throw new ProblemException("UnixUserAvailableIdHelper has not been initialised"); } Optional<Long> next = cachedSearchingAvailability.getNext(); if (!next.isPresent()) { throw new ProblemException("There is no more unix user id available"); } return next.get(); }
public void resourceAdd(IPResource resource) { resourcesToAdd.add(resource); // Check for conflicts if (resourceCheckInList(resource, resourcesToUpdate) || resourceCheckInListIds(resource, resourcesToDelete)) { throw new ResourcePrimaryKeyCollisionException(); } }
protected List<IPResource> linkFindAllByFromResourceAndLinkType(List<Tuple3<IPResource, String, IPResource>> previousLinks, IPResource fromResource, String linkType) { if (fromResource.getInternalId() == null) { throw new ResourceNotFromRepositoryException(fromResource); } return previousLinks.stream().filter( // it -> { return fromResource.getInternalId().equals(it.getA().getInternalId()) && // linkType.equals(it.getB()); }) // .map(it -> it.getC()) // .collect(Collectors.toList()); }
private void validate(MariaDBDatabase resource) { if (blacklisted.contains(resource.getName().toLowerCase())) { throw new IllegalUpdateException("That database name is blacklisted"); } }
public static long getNextAvailableId() { if (cachedSearchingAvailability == null) { throw new ProblemException("UnixUserAvailableIdHelper has not been initialised"); } Optional<Long> next = cachedSearchingAvailability.getNext(); if (!next.isPresent()) { throw new ProblemException("There is no more unix user id available"); } return next.get(); }
@SuppressWarnings("unchecked") protected <T extends IPResource> List<T> linkFindAllByFromResourceAndLinkTypeAndToResourceClass(List<Tuple3<IPResource, String, IPResource>> previousLinks, R fromResource, String linkType, Class<T> toResourceType) { if (fromResource.getInternalId() == null) { throw new ResourceNotFromRepositoryException(fromResource); } return previousLinks.stream().filter( // it -> { return fromResource.getInternalId().equals(it.getA().getInternalId()) && // linkType.equals(it.getB()) && // toResourceType.isInstance(it.getC()); }) // .map(it -> (T) it.getC()) // .collect(Collectors.toList()); }
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)); }
private void validate(MariaDBUser resource) { if (blacklisted.contains(resource.getName().toLowerCase())) { throw new IllegalUpdateException("That user name is blacklisted"); } }
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 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) { // 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 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); }
@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())); } }