public static TenantName defaultName() { return from("default"); }
@Override public boolean equals(Object other) { if (this == other) return true; if (other == null || getClass() != other.getClass()) return false; ApplicationId rhs = (ApplicationId) other; return tenant.equals(rhs.tenant) && application.equals(rhs.application) && instance.equals(rhs.instance); }
public Builder() { this.tenant = TenantName.defaultName(); this.application = null; this.instance = InstanceName.defaultName(); }
/** * Create a {@link TenantName} with a given name. * * @param name Name of tenant. * @return instance of {@link TenantName}. */ public static TenantName from(String name) { return new TenantName(name); }
@Override public int compareTo(ApplicationId other) { int diff; diff = tenant.compareTo(other.tenant); if (diff != 0) { return diff; } diff = application.compareTo(other.application); if (diff != 0) { return diff; } diff = instance.compareTo(other.instance); if (diff != 0) { return diff; } return 0; }
/** Returns an application id where all fields are "default" */ public static ApplicationId defaultId() { return new ApplicationId(TenantName.defaultName(), ApplicationName.defaultName(), InstanceName.defaultName()); }
@Override public Map<ApplicationInstanceReference, ApplicationInstance> getAllApplicationInstances() { // Convert apps information to the response payload to return Map<ApplicationInstanceReference, ApplicationInstance> status = new HashMap<>(); for (Map.Entry<ApplicationId, MockDeployer.ApplicationContext> app : apps.entrySet()) { Set<ServiceInstance> serviceInstances = new HashSet<>(); for (Node node : nodeRepository.getNodes(app.getValue().id(), Node.State.active)) { serviceInstances.add(new ServiceInstance(new ConfigId("configid"), new HostName(node.hostname()), getHostStatus(node.hostname()))); } Set<ServiceCluster> serviceClusters = new HashSet<>(); serviceClusters.add(new ServiceCluster(new ClusterId(app.getValue().clusterContexts().get(0).cluster().id().value()), new ServiceType("serviceType"), serviceInstances)); TenantId tenantId = new TenantId(app.getKey().tenant().value()); ApplicationInstanceId applicationInstanceId = new ApplicationInstanceId(app.getKey().application().value()); status.put(new ApplicationInstanceReference(tenantId, applicationInstanceId), new ApplicationInstance(tenantId, applicationInstanceId, serviceClusters)); } return status; }
public Builder tenant(String ten) { return tenant(TenantName.from(ten)); }
private boolean hostsOnly(TenantName tenant, Optional<String> parentHostname) { if ( ! parentHostname.isPresent()) return true; // yes, as host is exclusive for (Node nodeOnHost : nodeRepository.list().childrenOf(parentHostname.get())) { if ( ! nodeOnHost.allocation().isPresent()) continue; if ( ! nodeOnHost.allocation().get().owner().tenant().equals(tenant)) return false; } return true; }
/** Creates a new TesterId for a tester of the given application. */ public static TesterId of(ApplicationId id) { return new TesterId(ApplicationId.from(id.tenant().value(), id.application().value(), id.instance().value() + suffix)); }
public static ApplicationId toApplicationId(String applicationIdString) { String[] parts = applicationIdString.split("\\."); if (parts.length != 3) throw new IllegalArgumentException("Application id must be on the form tenant.application.instance, got '" + applicationIdString + "'"); return ApplicationId.from(TenantName.from(parts[0]), ApplicationName.from(parts[1]), InstanceName.from(parts[2])); }
/** * If a parent host is given, and it hosts another tenant with an application which requires exclusive access * to the physical host, then we cannot host this application on it. */ private boolean exclusiveTo(TenantName tenant, Optional<String> parentHostname) { if ( ! parentHostname.isPresent()) return true; for (Node nodeOnHost : nodeRepository.list().childrenOf(parentHostname.get())) { if ( ! nodeOnHost.allocation().isPresent()) continue; if ( nodeOnHost.allocation().get().membership().cluster().isExclusive() && ! nodeOnHost.allocation().get().owner().tenant().equals(tenant)) return false; } return true; }
public String toShortString() { return tenant().value() + "." + application().value() + ( instance().isDefault() ? "" : "." + instance().value() ); }
public static ApplicationId toApplicationId(ApplicationInstanceReference appRef) { String appNameStr = appRef.asString(); String[] appNameParts = appNameStr.split(":"); // Env, region and instance seems to be optional due to the hardcoded config server app // Assume here that first two are tenant and application name. if (appNameParts.length == 2) { return ApplicationId.from(TenantName.from(appNameParts[0]), ApplicationName.from(appNameParts[1]), InstanceName.defaultName()); } // Other normal application should have 5 parts. if (appNameParts.length != 5) { throw new IllegalArgumentException("Application reference not valid (not 5 parts): " + appRef); } return ApplicationId.from(TenantName.from(appNameParts[0]), ApplicationName.from(appNameParts[1]), InstanceName.from(appNameParts[4])); }
@Override public void getConfig(ApplicationIdConfig.Builder builder) { builder.tenant(applicationId.tenant().value()); builder.application(applicationId.application().value()); builder.instance(applicationId.instance().value()); }
public static ApplicationId from(String tenant, String application, String instance) { return new ApplicationId(TenantName.from(tenant), ApplicationName.from(application), InstanceName.from(instance)); }
private void toSlime(ApplicationId id, Cursor object) { object.setString("tenant", id.tenant().value()); object.setString("application", id.application().value()); object.setString("instance", id.instance().value()); }
public ApplicationId(ApplicationIdConfig config) { this(TenantName.from(config.tenant()), ApplicationName.from(config.application()), InstanceName.from(config.instance())); }
/** Creates an returns the path to the lock for this application */ private Path lockPath(ApplicationId application) { Path lockPath = lockRoot .append(application.tenant().value()) .append(application.application().value()) .append(application.instance().value()); curatorDatabase.create(lockPath); return lockPath; }