if (OpsContext.isConfigure()) {
if (assignedTo == null) {
List<GitService> gitServices = platformLayer.listItems(GitService.class);
if (gitServices.size() == 0) {
throw new OpsException("No git service found");
}
GitService gitService = RandomChooser.chooseRandom(gitServices);
if (gitService == null) {
throw new IllegalStateException();
}
assignedTo = gitService.getKey();
platformLayer.addTag(model.getKey(), Tag.ASSIGNED_TO.build(assignedTo));
}
}
GitService gitService = null;
if (assignedTo != null) {
gitService = platformLayer.getItem(assignedTo, GitService.class);
}
if (OpsContext.isDelete()) {
if (gitService == null) {
log.info("Deleting, but not assigned to a server; nothing to do");
getRecursionState().setPreventRecursion(true);
return;
}
}
if (gitService == null) {
throw new OpsException("No git servers found");
}
if (gitService.getState() != ManagedItemState.ACTIVE) {
throw new OpsException("Server not yet active: " + gitService);
}
Machine machine = instances.findMachine(gitService);
if (machine == null) {
throw new OpsException("Server machine not found:" + gitService);
}
SshKey sshKey = service.getSshKey();
OpsTarget target = machine.getTarget(sshKey);