use of com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleBaseImage in project halyard by spinnaker.
the class GoogleBakeryDefaultsValidator method validate.
@Override
public void validate(ConfigProblemSetBuilder p, GoogleBakeryDefaults n) {
DaemonTaskHandler.message("Validating " + n.getNodeName() + " with " + GoogleBakeryDefaultsValidator.class.getSimpleName());
String zone = n.getZone();
String network = n.getNetwork();
String networkProjectId = n.getNetworkProjectId();
List<GoogleBaseImage> baseImages = n.getBaseImages();
if (StringUtils.isEmpty(zone) && StringUtils.isEmpty(network) && CollectionUtils.isEmpty(baseImages)) {
return;
} else if (CollectionUtils.isEmpty(credentialsList)) {
return;
}
if (StringUtils.isEmpty(zone)) {
p.addProblem(Problem.Severity.ERROR, "No zone supplied for google bakery defaults.");
} else {
int i = 0;
boolean foundZone = false;
while (!foundZone && i < credentialsList.size()) {
GoogleNamedAccountCredentials credentials = credentialsList.get(i);
try {
credentials.getCompute().zones().get(credentials.getProject(), zone).execute();
foundZone = true;
} catch (Exception e) {
}
i++;
}
if (!foundZone) {
p.addProblem(Problem.Severity.ERROR, "Zone " + zone + " not found via any configured google account.");
}
}
if (StringUtils.isEmpty(network)) {
p.addProblem(Problem.Severity.ERROR, "No network supplied for google bakery defaults.");
} else {
int j = 0;
boolean foundNetwork = false;
while (!foundNetwork && j < credentialsList.size()) {
GoogleNamedAccountCredentials credentials = credentialsList.get(j);
try {
String project = !StringUtils.isEmpty(networkProjectId) ? networkProjectId : credentials.getProject();
credentials.getCompute().networks().get(project, network).execute();
foundNetwork = true;
} catch (Exception e) {
}
j++;
}
if (!foundNetwork) {
p.addProblem(Problem.Severity.ERROR, "Network " + network + " not found via any configured google account.");
}
}
GoogleBaseImageValidator googleBaseImageValidator = new GoogleBaseImageValidator(credentialsList, halyardVersion);
baseImages.forEach(googleBaseImage -> googleBaseImageValidator.validate(p, googleBaseImage));
}
use of com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleBaseImage in project halyard by spinnaker.
the class GoogleAddBaseImageCommand method buildBaseImage.
@Override
protected BaseImage buildBaseImage(String baseImageId) {
GoogleBaseImage baseImage = new GoogleBaseImage();
GoogleBaseImage.GoogleImageSettings imageSettings = new GoogleBaseImage.GoogleImageSettings();
imageSettings.setImageFamily(isImageFamily);
baseImage.setBaseImage(imageSettings);
GoogleBaseImage.GoogleVirtualizationSettings virtualizationSettings = new GoogleBaseImage.GoogleVirtualizationSettings();
virtualizationSettings.setSourceImage(sourceImage);
virtualizationSettings.setSourceImageFamily(sourceImageFamily);
baseImage.setVirtualizationSettings(virtualizationSettings);
return baseImage;
}
use of com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleBaseImage in project halyard by spinnaker.
the class GoogleBaseImageValidator method validate.
@Override
public void validate(ConfigProblemSetBuilder p, GoogleBaseImage n) {
String sourceImage = n.getVirtualizationSettings().getSourceImage();
String sourceImageFamily = n.getVirtualizationSettings().getSourceImageFamily();
if (StringUtils.isEmpty(sourceImage) && StringUtils.isEmpty(sourceImageFamily)) {
p.addProblem(Problem.Severity.ERROR, "Either source image or source image family must be specified for " + n.getBaseImage().getId() + ".");
}
if (!StringUtils.isEmpty(sourceImage)) {
int i = 0;
boolean[] foundSourceImageHolder = new boolean[1];
while (!foundSourceImageHolder[0] && i < credentialsList.size()) {
GoogleNamedAccountCredentials credentials = credentialsList.get(i);
List<String> imageProjects = Lists.newArrayList(credentials.getProject());
imageProjects.addAll(credentials.getImageProjects());
imageProjects.addAll(baseImageProjects);
Compute compute = credentials.getCompute();
BatchRequest imageListBatch = buildBatchRequest(compute);
JsonBatchCallback<ImageList> imageListCallback = new JsonBatchCallback<ImageList>() {
@Override
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
p.addProblem(Problem.Severity.ERROR, "Error locating " + sourceImage + " in these projects: " + imageProjects + ": " + e.getMessage() + ".");
}
@Override
public void onSuccess(ImageList imageList, HttpHeaders responseHeaders) throws IOException {
// No need to look through these images if the requested image was already found.
if (!foundSourceImageHolder[0]) {
if (imageList.getItems() != null) {
foundSourceImageHolder[0] = imageList.getItems().stream().filter(image -> image.getName().equals(sourceImage)).findFirst().isPresent();
}
}
}
};
try {
for (String imageProject : imageProjects) {
compute.images().list(imageProject).queue(imageListBatch, imageListCallback);
}
imageListBatch.execute();
} catch (IOException e) {
p.addProblem(Problem.Severity.ERROR, "Error locating " + sourceImage + " in these projects: " + imageProjects + ": " + e.getMessage() + ".");
}
i++;
}
if (!foundSourceImageHolder[0]) {
p.addProblem(Problem.Severity.ERROR, "Image " + sourceImage + " not found via any configured google account.");
}
}
if (!StringUtils.isEmpty(sourceImageFamily)) {
int i = 0;
boolean[] foundSourceImageFamilyHolder = new boolean[1];
while (!foundSourceImageFamilyHolder[0] && i < credentialsList.size()) {
GoogleNamedAccountCredentials credentials = credentialsList.get(i);
List<String> imageProjects = Lists.newArrayList(credentials.getProject());
imageProjects.addAll(credentials.getImageProjects());
imageProjects.addAll(baseImageProjects);
Compute compute = credentials.getCompute();
BatchRequest imageListBatch = buildBatchRequest(compute);
JsonBatchCallback<ImageList> imageListCallback = new JsonBatchCallback<ImageList>() {
@Override
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
p.addProblem(Problem.Severity.ERROR, "Error locating " + sourceImageFamily + " in these projects: " + imageProjects + ": " + e.getMessage() + ".");
}
@Override
public void onSuccess(ImageList imageList, HttpHeaders responseHeaders) throws IOException {
// No need to look through these images if the requested image family was already found.
if (!foundSourceImageFamilyHolder[0]) {
if (imageList.getItems() != null) {
foundSourceImageFamilyHolder[0] = imageList.getItems().stream().filter(image -> sourceImageFamily.equals(image.getFamily())).findFirst().isPresent();
}
}
}
};
try {
for (String imageProject : imageProjects) {
compute.images().list(imageProject).queue(imageListBatch, imageListCallback);
}
imageListBatch.execute();
} catch (IOException e) {
p.addProblem(Problem.Severity.ERROR, "Error locating " + sourceImageFamily + " in these projects: " + imageProjects + ": " + e.getMessage() + ".");
}
i++;
}
if (!foundSourceImageFamilyHolder[0]) {
p.addProblem(Problem.Severity.ERROR, "Image family " + sourceImageFamily + " not found via any configured google account.");
}
}
if (StringUtils.isEmpty(n.getBaseImage().getPackageType())) {
p.addProblem(Problem.Severity.ERROR, "Package type must be specified for " + n.getBaseImage().getId() + ".");
}
}
Aggregations