return computeRepository.getInstances(project.getId()).find(instanceId);
}
public InstanceData replaceMetadata(Project project, long instanceId, Map<String, String> model, boolean replaceAll)
throws CloudException {
InstanceData instance = findInstance(project, instanceId);
if (instance == null) {
throw new IllegalArgumentException("Instance not found: " + instanceId);
}
InstanceData.Builder b = InstanceData.newBuilder(instance);
if (replaceAll) {
b.clearMetadata();
MetadataData.Builder mb = b.getMetadataBuilder();
for (Entry<String, String> entry : model.entrySet()) {
MetadataEntryData.Builder eb = mb.addEntryBuilder();
eb.setKey(entry.getKey());
eb.setValue(entry.getValue());
}
} else {
MetadataData.Builder mb = b.getMetadataBuilder();
for (Entry<String, String> entry : model.entrySet()) {
if (!setMetadataKey(mb, entry.getKey(), entry.getValue())) {
throw new IllegalArgumentException();
}
}
}
InstanceData updated = computeRepository.getInstances(project.getId()).update(b);
magicMetadata.instanceUpdated(project, updated);
return updated;
}