Skip to content

Commit

Permalink
Resolve assignment before using in a filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Apr 4, 2012
1 parent 5086d76 commit 4a2c1a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Expand Up @@ -12,6 +12,7 @@
import com.proofpoint.galaxy.shared.Assignment;
import com.proofpoint.galaxy.shared.HttpUriBuilder;
import com.proofpoint.galaxy.shared.Installation;
import com.proofpoint.galaxy.shared.InstallationUtils;
import com.proofpoint.galaxy.shared.Repository;
import com.proofpoint.galaxy.shared.SlotStatus;

Expand Down Expand Up @@ -352,7 +353,7 @@ public static class AssignablePredicate implements Predicate<AgentStatus>

public AssignablePredicate(Assignment assignment, boolean allowDuplicateInstallationsOnAnAgent, Repository repository)
{
this.assignment = assignment;
this.assignment = InstallationUtils.resolveAssignment(repository, assignment);
this.allowDuplicateInstallationsOnAnAgent = allowDuplicateInstallationsOnAnAgent;
this.repository = repository;
}
Expand Down
Expand Up @@ -19,14 +19,8 @@ public class InstallationUtils
{
public static Installation toInstallation(Repository repository, Assignment assignment)
{
// resolve assignment
String resolvedBinary = repository.binaryResolve(assignment.getBinary());
Preconditions.checkArgument(resolvedBinary != null, "Unknown binary " + assignment.getBinary());
assignment = resolveAssignment(repository, assignment);

String resolvedConfig = repository.configResolve(assignment.getConfig());
Preconditions.checkArgument(resolvedConfig != null, "Unknown config " + assignment.getConfig());

assignment = new Assignment(resolvedBinary, resolvedConfig);

// load resources
Map<String, Integer> resources = readResources(repository, assignment);
Expand All @@ -44,6 +38,19 @@ public static Installation toInstallation(Repository repository, Assignment assi
resources);
}

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;
}

public static boolean resourcesAreAvailable(Map<String, Integer> availableResources, Map<String, Integer> requiredResources)
{
for (Entry<String, Integer> entry : requiredResources.entrySet()) {
Expand Down

0 comments on commit 4a2c1a1

Please sign in to comment.