@Override public void validate(ConfigProblemSetBuilder ps, PersistentStorage n) { PersistentStore.PersistentStoreType persistentStoreType = n.getPersistentStoreType(); if (persistentStoreType == null) { ps.addProblem(Severity.WARNING, "Your deployment will most likely fail until you configure and enable a persistent store."); } } }
public void setPersistentStore(String deploymentName, PersistentStore newPersistentStore) { PersistentStorage persistentStorage = getPersistentStorage(deploymentName); switch (newPersistentStore.persistentStoreType()) { case S3: persistentStorage.setS3((S3PersistentStore) newPersistentStore); break; case GCS: persistentStorage.setGcs((GcsPersistentStore) newPersistentStore); break; case AZS: persistentStorage.setAzs((AzsPersistentStore) newPersistentStore); break; case ORACLE: persistentStorage.setOracle((OraclePersistentStore) newPersistentStore); break; case ORACLEBMCS: persistentStorage.setOraclebmcs((OracleBMCSPersistentStore) newPersistentStore); break; default: throw new RuntimeException("Unknown persistent store " + newPersistentStore.persistentStoreType()); } }
@Override protected void executeThis() { String currentDeployment = getCurrentDeployment(); // Disable validation here, since we don't want an illegal config to prevent us from fixing it. PersistentStorage persistentStorage = new OperationHandler<PersistentStorage>() .setFailureMesssage("Failed to get persistent storage.") .setOperation(Daemon.getPersistentStorage(currentDeployment, false)) .get(); int originalHash = persistentStorage.hashCode(); persistentStorage.setPersistentStoreType(isSet(type) ? type : persistentStorage.getPersistentStoreType()); if (originalHash == persistentStorage.hashCode()) { AnsiUi.failure("No changes supplied."); return; } new OperationHandler<Void>() .setOperation(Daemon.setPersistentStorage(currentDeployment, !noValidate, persistentStorage)) .setFailureMesssage("Failed to edit persistent storage.") .setSuccessMessage("Successfully edited persistent storage.") .get(); } }
protected Optional<Profile> generateAwsProfile(DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints, String spinnakerHome) { String name = "aws/front50-credentials" + spinnakerHome.replace("/", "_"); PersistentStore.PersistentStoreType type = deploymentConfiguration.getPersistentStorage().getPersistentStoreType(); S3PersistentStore store = deploymentConfiguration.getPersistentStorage().getS3(); if (type == PersistentStore.PersistentStoreType.S3 && !StringUtils.isEmpty(store.getAccessKeyId()) && !StringUtils.isEmpty(store.getSecretAccessKey())) { String outputFile = awsCredentialsProfileFactoryBuilder.getOutputFile(spinnakerHome); return Optional.of(awsCredentialsProfileFactoryBuilder .setArtifact(SpinnakerArtifact.FRONT50) .setAccessKeyId(store.getAccessKeyId()) .setSecretAccessKey(store.getSecretAccessKey()) .build() .getProfile(name, outputFile, deploymentConfiguration, endpoints)); } else { return Optional.empty(); } }
PersistentStorage persistentStorage = deploymentConfiguration.getPersistentStorage(); if (persistentStorage.getPersistentStoreType() == null) { throw new HalException(Problem.Severity.FATAL, "No persistent storage type was configured."); Map<String, Map<String, Object>> persistentStorageMap = new HashMap<>(); NodeIterator children = persistentStorage.getChildren(); Node child = children.getNext(); while (child != null) { persistentStoreMap.put("enabled", persistentStoreType.equals(persistentStorage.getPersistentStoreType()));
public static Supplier<PersistentStore> getPersistentStore(String deploymentName, String persistentStoreType, boolean validate) { return () -> { Object rawPersistentStore = ResponseUnwrapper.get(getService().getPersistentStore(deploymentName, persistentStoreType, validate)); return getObjectMapper().convertValue(rawPersistentStore, PersistentStorage.translatePersistentStoreType(persistentStoreType)); }; }
public PersistentStorage getPersistentStorage(String deploymentName) { NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setPersistentStorage(); List<PersistentStorage> matching = lookupService.getMatchingNodesOfType(filter, PersistentStorage.class); switch (matching.size()) { case 0: PersistentStorage persistentStorage = new PersistentStorage(); setPersistentStorage(deploymentName, persistentStorage); return persistentStorage; case 1: return matching.get(0); default: throw new RuntimeException("It shouldn't be possible to have multiple persistentStorage nodes. This is a bug."); } }
@Override protected void executeThis() { String currentDeployment = getCurrentDeployment(); // Disable validation here, since we don't want an illegal config to prevent us from fixing it. PersistentStorage persistentStorage = new OperationHandler<PersistentStorage>() .setFailureMesssage("Failed to get persistent storage.") .setOperation(Daemon.getPersistentStorage(currentDeployment, false)) .get(); int originalHash = persistentStorage.hashCode(); persistentStorage.setPersistentStoreType(isSet(type) ? type : persistentStorage.getPersistentStoreType()); if (originalHash == persistentStorage.hashCode()) { AnsiUi.failure("No changes supplied."); return; } new OperationHandler<Void>() .setOperation(Daemon.setPersistentStorage(currentDeployment, !noValidate, persistentStorage)) .setFailureMesssage("Failed to edit persistent storage.") .setSuccessMessage("Successfully edited persistent storage.") .get(); } }
protected Optional<Profile> generateAwsProfile(DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints, String spinnakerHome) { String name = "aws/front50-credentials" + spinnakerHome.replace("/", "_"); PersistentStore.PersistentStoreType type = deploymentConfiguration.getPersistentStorage().getPersistentStoreType(); S3PersistentStore store = deploymentConfiguration.getPersistentStorage().getS3(); if (type == PersistentStore.PersistentStoreType.S3 && !StringUtils.isEmpty(store.getAccessKeyId()) && !StringUtils.isEmpty(store.getSecretAccessKey())) { String outputFile = awsCredentialsProfileFactoryBuilder.getOutputFile(spinnakerHome); return Optional.of(awsCredentialsProfileFactoryBuilder .setArtifact(SpinnakerArtifact.FRONT50) .setAccessKeyId(store.getAccessKeyId()) .setSecretAccessKey(store.getSecretAccessKey()) .build() .getProfile(name, outputFile, deploymentConfiguration, endpoints)); } else { return Optional.empty(); } }
PersistentStorage persistentStorage = deploymentConfiguration.getPersistentStorage(); if (persistentStorage.getPersistentStoreType() == null) { throw new HalException(Problem.Severity.FATAL, "No persistent storage type was configured."); Map<String, Map<String, Object>> persistentStorageMap = new HashMap<>(); NodeIterator children = persistentStorage.getChildren(); Node child = children.getNext(); while (child != null) { persistentStoreMap.put("enabled", persistentStoreType.equals(persistentStorage.getPersistentStoreType()));
public static Supplier<PersistentStore> getPersistentStore(String deploymentName, String persistentStoreType, boolean validate) { return () -> { Object rawPersistentStore = ResponseUnwrapper.get(getService().getPersistentStore(deploymentName, persistentStoreType, validate)); return getObjectMapper().convertValue(rawPersistentStore, PersistentStorage.translatePersistentStoreType(persistentStoreType)); }; }
public PersistentStorage getPersistentStorage(String deploymentName) { NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setPersistentStorage(); List<PersistentStorage> matching = lookupService.getMatchingNodesOfType(filter, PersistentStorage.class); switch (matching.size()) { case 0: PersistentStorage persistentStorage = new PersistentStorage(); setPersistentStorage(deploymentName, persistentStorage); return persistentStorage; case 1: return matching.get(0); default: throw new RuntimeException("It shouldn't be possible to have multiple persistentStorage nodes. This is a bug."); } }
@Override public void validate(ConfigProblemSetBuilder ps, PersistentStorage n) { PersistentStore.PersistentStoreType persistentStoreType = n.getPersistentStoreType(); if (persistentStoreType == null) { ps.addProblem(Severity.WARNING, "Your deployment will most likely fail until you configure and enable a persistent store."); } } }
public void setPersistentStore(String deploymentName, PersistentStore newPersistentStore) { PersistentStorage persistentStorage = getPersistentStorage(deploymentName); switch (newPersistentStore.persistentStoreType()) { case S3: persistentStorage.setS3((S3PersistentStore) newPersistentStore); break; case GCS: persistentStorage.setGcs((GcsPersistentStore) newPersistentStore); break; case AZS: persistentStorage.setAzs((AzsPersistentStore) newPersistentStore); break; case ORACLE: persistentStorage.setOracle((OraclePersistentStore) newPersistentStore); break; case ORACLEBMCS: persistentStorage.setOraclebmcs((OracleBMCSPersistentStore) newPersistentStore); break; default: throw new RuntimeException("Unknown persistent store " + newPersistentStore.persistentStoreType()); } }
@RequestMapping(value = "/{persistentStoreType:.+}", method = RequestMethod.PUT) DaemonTask<Halconfig, Void> setPersistentStore(@PathVariable String deploymentName, @PathVariable String persistentStoreType, @ModelAttribute ValidationSettings validationSettings, @RequestBody Object rawPersistentStore) { PersistentStore persistentStore = objectMapper.convertValue(rawPersistentStore, PersistentStorage.translatePersistentStoreType(persistentStoreType)); return GenericUpdateRequest.<PersistentStore>builder(halconfigParser) .stagePath(halconfigDirectoryStructure.getStagingPath(deploymentName)) .updater(p -> persistentStorageService.setPersistentStore(deploymentName, p)) .validator(() -> persistentStorageService.validatePersistentStore(deploymentName, persistentStoreType)) .description("Edit persistent store") .build() .execute(validationSettings, persistentStore); } }
public ProblemSet validatePersistentStorage(String deploymentName) { PersistentStorage storage = getPersistentStorage(deploymentName); NodeFilter filter = new NodeFilter() .setDeployment(deploymentName) .setPersistentStorage(); if (storage.getPersistentStoreType() != null) { filter.setPersistentStore(storage.getPersistentStoreType().getId()); } return validateService.validateMatchingFilter(filter); }
public ProblemSet validatePersistentStorage(String deploymentName) { PersistentStorage storage = getPersistentStorage(deploymentName); NodeFilter filter = new NodeFilter() .setDeployment(deploymentName) .setPersistentStorage(); if (storage.getPersistentStoreType() != null) { filter.setPersistentStore(storage.getPersistentStoreType().getId()); } return validateService.validateMatchingFilter(filter); }
public ProblemSet validateDeployment(String deploymentName) { PersistentStorage storage = storageService.getPersistentStorage(deploymentName); NodeFilter filter = new NodeFilter() .setDeployment(deploymentName) .withAnyProvider() .withAnyAccount() .setFeatures() .setSecurity(); if (storage.getPersistentStoreType() != null) { filter.setPersistentStore(storage.getPersistentStoreType().getId()); } return validateService.validateMatchingFilter(filter); }
public ProblemSet validateDeployment(String deploymentName) { PersistentStorage storage = storageService.getPersistentStorage(deploymentName); NodeFilter filter = new NodeFilter() .setDeployment(deploymentName) .withAnyProvider() .withAnyAccount() .setFeatures() .setSecurity(); if (storage.getPersistentStoreType() != null) { filter.setPersistentStore(storage.getPersistentStoreType().getId()); } return validateService.validateMatchingFilter(filter); }