@Override protected AbstractCanaryAccount editAccount(GoogleCanaryAccount account) { account.setProject(isSet(project) ? project : account.getProject()); account.setJsonPath(isSet(jsonPath) ? jsonPath : account.getJsonPath()); account.setBucket(isSet(bucket) ? bucket : account.getBucket()); account.setRootFolder(isSet(rootFolder) ? rootFolder : account.getRootFolder()); account.setBucketLocation(isSet(bucketLocation) ? bucketLocation : account.getBucketLocation()); return account; } }
@Override protected AbstractCanaryAccount buildAccount(Canary canary, String accountName) { GoogleCanaryAccount account = (GoogleCanaryAccount)new GoogleCanaryAccount().setName(accountName); account.setProject(project).setJsonPath(jsonPath); account.setBucket(bucket).setBucketLocation(bucketLocation); account.setRootFolder(isSet(rootFolder) ? rootFolder : account.getRootFolder()); GoogleCanaryServiceIntegration googleCanaryServiceIntegration = (GoogleCanaryServiceIntegration)CanaryUtils.getServiceIntegrationByClass(canary, GoogleCanaryServiceIntegration.class); if (googleCanaryServiceIntegration.isStackdriverEnabled()) { account.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.METRICS_STORE); } if (googleCanaryServiceIntegration.isGcsEnabled()) { account.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.CONFIGURATION_STORE); account.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.OBJECT_STORE); } return account; }
GoogleNamedAccountCredentials credentials = canaryAccount.getNamedAccountCredentials(halyardVersion, p); String jsonPath = canaryAccount.getJsonPath(); canaryAccount.getBucket(), canaryAccount.getBucketLocation(), canaryAccount.getRootFolder(), canaryAccount.getProject(), jsonPath != null ? jsonPath : "", "halyard", p.addProblem(Severity.ERROR, "Failed to ensure the required bucket \"" + canaryAccount.getBucket() + "\" exists: " + e.getMessage());
@JsonIgnore public GoogleNamedAccountCredentials getNamedAccountCredentials(String version, ConfigProblemSetBuilder p) { String jsonKey = null; if (!StringUtils.isEmpty(getJsonPath())) { jsonKey = ValidatingFileReader.contents(p, getJsonPath()); if (StringUtils.isEmpty(getProject())) { p.addProblem(Problem.Severity.ERROR, "No google project supplied."); return null; .name(getName()) .jsonKey(jsonKey) .project(getProject()) .applicationName("halyard " + version) .liveLookupsEnabled(false) } catch (Exception e) { p.addProblem(Problem.Severity.ERROR, "Error instantiating Google credentials: " + e.getMessage() + ".") .setRemediation("Do the provided credentials have access to project " + getProject() + "?"); return null;
@Override public void validate(ConfigProblemSetBuilder p, AbstractCanaryAccount n) { super.validate(p, n); GoogleCanaryAccount canaryAccount = (GoogleCanaryAccount)n; DaemonTaskHandler.message("Validating " + n.getNodeName() + " with " + GoogleCanaryAccountValidator.class.getSimpleName()); GoogleNamedAccountCredentials credentials = canaryAccount.getNamedAccountCredentials(halyardVersion, p); if (credentials == null) { return; } try { Compute compute = credentials.getCompute(); compute.projects().get(canaryAccount.getProject()).execute(); } catch (IOException e) { p.addProblem(Severity.ERROR, "Failed to load project \"" + canaryAccount.getProject() + "\": " + e.getMessage() + "."); } } }
@Override public void validate(ConfigProblemSetBuilder p, GoogleCanaryServiceIntegration n) { GoogleCanaryAccountValidator googleCanaryAccountValidator = new GoogleCanaryAccountValidator(halyardVersion); n.getAccounts().forEach(a -> googleCanaryAccountValidator.validate(p, a)); if (n.isGcsEnabled()) { List<GoogleCanaryAccount> accountsWithBucket = n.getAccounts() .stream() .filter(a -> a.getBucket() != null) .collect(Collectors.toList()); if (CollectionUtils.isEmpty(accountsWithBucket)) { p.addProblem(Problem.Severity.ERROR, "At least one Google account must specify a bucket if GCS is enabled."); } } } }
@Override protected AbstractCanaryAccount emptyAccount() { return new GoogleCanaryAccount(); } }
googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.METRICS_STORE)); } else { googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().remove(AbstractCanaryServiceIntegration.SupportedTypes.METRICS_STORE)); googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.CONFIGURATION_STORE)); googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.OBJECT_STORE)); } else { googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().remove(AbstractCanaryServiceIntegration.SupportedTypes.CONFIGURATION_STORE)); googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().remove(AbstractCanaryServiceIntegration.SupportedTypes.OBJECT_STORE));
@JsonIgnore public GoogleNamedAccountCredentials getNamedAccountCredentials(String version, ConfigProblemSetBuilder p) { String jsonKey = null; if (!StringUtils.isEmpty(getJsonPath())) { jsonKey = ValidatingFileReader.contents(p, getJsonPath()); if (StringUtils.isEmpty(getProject())) { p.addProblem(Problem.Severity.ERROR, "No google project supplied."); return null; .name(getName()) .jsonKey(jsonKey) .project(getProject()) .applicationName("halyard " + version) .liveLookupsEnabled(false) } catch (Exception e) { p.addProblem(Problem.Severity.ERROR, "Error instantiating Google credentials: " + e.getMessage() + ".") .setRemediation("Do the provided credentials have access to project " + getProject() + "?"); return null;
@Override public void validate(ConfigProblemSetBuilder p, GoogleCanaryServiceIntegration n) { GoogleCanaryAccountValidator googleCanaryAccountValidator = new GoogleCanaryAccountValidator() .setHalyardVersion(halyardVersion) .setRegistry(registry) .setTaskScheduler(taskScheduler); if (n.isGcsEnabled()) { List<GoogleCanaryAccount> accountsWithBucket = n.getAccounts() .stream() .filter(a -> a.getBucket() != null) .collect(Collectors.toList()); if (CollectionUtils.isEmpty(accountsWithBucket)) { p.addProblem(Problem.Severity.ERROR, "At least one Google account must specify a bucket if GCS is enabled."); } else { accountsWithBucket.forEach(a -> googleCanaryAccountValidator.validate(p, a)); } } } }
@Override protected AbstractCanaryAccount emptyAccount() { return new GoogleCanaryAccount(); } }
googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.METRICS_STORE)); } else { googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().remove(AbstractCanaryServiceIntegration.SupportedTypes.METRICS_STORE)); googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.CONFIGURATION_STORE)); googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.OBJECT_STORE)); } else { googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().remove(AbstractCanaryServiceIntegration.SupportedTypes.CONFIGURATION_STORE)); googleCanaryServiceIntegration.getAccounts().forEach(a -> a.getSupportedTypes().remove(AbstractCanaryServiceIntegration.SupportedTypes.OBJECT_STORE));
@Override protected AbstractCanaryAccount editAccount(GoogleCanaryAccount account) { account.setProject(isSet(project) ? project : account.getProject()); account.setJsonPath(isSet(jsonPath) ? jsonPath : account.getJsonPath()); account.setBucket(isSet(bucket) ? bucket : account.getBucket()); account.setRootFolder(isSet(rootFolder) ? rootFolder : account.getRootFolder()); account.setBucketLocation(isSet(bucketLocation) ? bucketLocation : account.getBucketLocation()); return account; } }
@Override protected AbstractCanaryAccount buildAccount(Canary canary, String accountName) { GoogleCanaryAccount account = (GoogleCanaryAccount)new GoogleCanaryAccount().setName(accountName); account.setProject(project).setJsonPath(jsonPath); account.setBucket(bucket).setBucketLocation(bucketLocation); account.setRootFolder(isSet(rootFolder) ? rootFolder : account.getRootFolder()); GoogleCanaryServiceIntegration googleCanaryServiceIntegration = (GoogleCanaryServiceIntegration)CanaryUtils.getServiceIntegrationByClass(canary, GoogleCanaryServiceIntegration.class); if (googleCanaryServiceIntegration.isStackdriverEnabled()) { account.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.METRICS_STORE); } if (googleCanaryServiceIntegration.isGcsEnabled()) { account.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.CONFIGURATION_STORE); account.getSupportedTypes().add(AbstractCanaryServiceIntegration.SupportedTypes.OBJECT_STORE); } return account; }