public static Assignment resolveAssignment(Repository repository, Assignment assignment) { // resolve assignment String resolvedBinary = repository.binaryResolve(assignment.getBinary()); Preconditions.checkArgument(resolvedBinary != null, "Unknown binary " + assignment.getBinary()); String resolvedConfig = repository.configResolve(assignment.getConfig()); Preconditions.checkArgument(resolvedConfig != null, "Unknown config " + assignment.getConfig()); assignment = new Assignment(resolvedBinary, resolvedConfig); return assignment; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Installation that = (Installation) o; if (!assignment.equals(that.assignment)) { return false; } return true; }
@Override public int hashCode() { return assignment.hashCode(); }
public Assignment toAssignment() { Assignment assignment = new Assignment(binary, config); return assignment; }
@JsonProperty public String getConfig() { if (assignment == null) { return null; } return assignment.getConfig(); }
@JsonProperty public String getBinary() { if (assignment == null) { return null; } return assignment.getBinary(); }
@Override public boolean apply(RemoteAgent agent) { for (RemoteSlot slot : agent.getSlots()) { if (repository.binaryEqualsIgnoreVersion(assignment.getBinary(), slot.status().getAssignment().getBinary()) && repository.configEqualsIgnoreVersion(assignment.getConfig(), slot.status().getAssignment().getConfig())) { return false; } } return true; } };
@JsonCreator public ExpectedSlotStatus( @JsonProperty("id") UUID id, @JsonProperty("status") SlotLifecycleState status, @JsonProperty("binary") String binarySpec, @JsonProperty("config") String configSpec) { this.id = id; this.status = status; this.assignment = new Assignment(binarySpec, configSpec); }
@Override public boolean apply(@Nullable SlotStatus slotStatus) { return slotStatus != null && glob.apply(slotStatus.getAssignment().getConfig()); } }
@Override public boolean apply(@Nullable SlotStatus slotStatus) { return slotStatus != null && glob.apply(slotStatus.getAssignment().getBinary()); } }
public static Installation toInstallation(Repository repository, Assignment assignment) { assignment = resolveAssignment(repository, assignment); // load resources Map<String, Integer> resources = readResources(repository, assignment); // create installation URI binaryUri = repository.binaryToHttpUri(assignment.getBinary()); Preconditions.checkNotNull(binaryUri, "Unknown binary %s", binaryUri); URI configUri = repository.configToHttpUri(assignment.getConfig()); Preconditions.checkNotNull(configUri, "Unknown config %s", configUri); return new Installation( repository.configShortName(assignment.getConfig()), assignment, binaryUri, configUri, resources); }
public Assignment upgradeAssignment(Repository repository, Assignment assignment) { Preconditions.checkNotNull(assignment, "assignment is null"); String binary = assignment.getBinary(); if (binaryVersion != null) { binary = repository.binaryUpgrade(binary, binaryVersion); Preconditions.checkArgument(binary != null, "Can not upgrade binary " + assignment.getBinary() + " to " + binaryVersion); } else{ Preconditions.checkArgument(repository.binaryToHttpUri(assignment.getBinary()) != null, "Can not locate existing binary " + assignment.getBinary() + " for upgrade"); } String config = assignment.getConfig(); if (configVersion != null) { config = repository.configUpgrade(config, configVersion); Preconditions.checkArgument(config != null, "Can not upgrade config " + assignment.getConfig() + " to " + configVersion); } else { Preconditions.checkArgument(repository.configToHttpUri(assignment.getConfig()) != null, "Can not locate existing config " + assignment.getConfig() + " for upgrade"); } return new Assignment(binary, config); }
public SlotStatus toSlotStatus(String instanceId) { Assignment assignment = null; if (binary != null) { assignment = new Assignment(binary, config); } Assignment expectedAssignment = null; if (expectedBinary != null) { assignment = new Assignment(expectedBinary, expectedConfig); } SlotLifecycleState expectedState = null; if (expectedStatus != null) { expectedState = SlotLifecycleState.valueOf(expectedStatus); } return SlotStatus.createSlotStatusWithExpectedState(id, self, externalUri, instanceId, location, SlotLifecycleState.valueOf(status), assignment, installPath, resources, expectedState, expectedAssignment, statusMessage); }
public static Map<String, Integer> readResources(Repository repository, Assignment assignment) { ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder(); InputSupplier<? extends InputStream> resourcesFile = newConfigEntrySupplier(repository, assignment.getConfig(), "galaxy-resources.properties"); if (resourcesFile != null) { try { Properties resources = new Properties(); resources.load(resourcesFile.getInput()); for (Entry<Object, Object> entry : resources.entrySet()) { builder.put((String) entry.getKey(), Integer.valueOf((String) entry.getValue())); } } catch (IOException ignored) { } } return builder.build(); } }
@Override public int hashCode() { int result = (nodeId != null ? nodeId.hashCode() : 0); result = 31 * result + (location != null ? location.hashCode() : 0); result = 31 * result + (deploymentDir != null ? deploymentDir.hashCode() : 0); result = 31 * result + (dataDir != null ? dataDir.hashCode() : 0); result = 31 * result + (assignment != null ? assignment.hashCode() : 0); result = 31 * result + (resources != null ? resources.hashCode() : 0); return result; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Deployment that = (Deployment) o; if (assignment != null ? !assignment.equals(that.assignment) : that.assignment != null) { return false; } if (dataDir != null ? !dataDir.equals(that.dataDir) : that.dataDir != null) { return false; } if (deploymentDir != null ? !deploymentDir.equals(that.deploymentDir) : that.deploymentDir != null) { return false; } if (location != null ? !location.equals(that.location) : that.location != null) { return false; } if (nodeId != null ? !nodeId.equals(that.nodeId) : that.nodeId != null) { return false; } if (resources != null ? !resources.equals(that.resources) : that.resources != null) { return false; } return true; }
List<String> split = ImmutableList.copyOf(Splitter.on("@").limit(2).split(assignment)); Preconditions.checkArgument(split.size() == 2, "Invalid canInstall filter %s", assignment); builder.addAssignableFilter(new Assignment(split.get(0), "@" + split.get(1)));
private String toBaseName(Installation installation) { String configSpec = installation.getAssignment().getConfig(); MavenCoordinates mavenCoordinates = MavenCoordinates.fromConfigGAV(configSpec); String baseName; if (mavenCoordinates != null) { baseName = mavenCoordinates.getArtifactId(); } else if (configSpec.startsWith("@")) { baseName = configSpec.substring(1); } else { baseName = configSpec; } return baseName; }