Search in sources :

Example 61 with HalException

use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.

the class LocalServiceProvider method getLocalService.

public <S> LocalService<S> getLocalService(SpinnakerService.Type type, Class<S> clazz) {
    Field serviceField = getField(type.getCanonicalName() + "service");
    if (serviceField == null) {
        return null;
    }
    serviceField.setAccessible(true);
    try {
        return (LocalService<S>) serviceField.get(this);
    } catch (IllegalAccessException e) {
        throw new HalException(Problem.Severity.FATAL, "Can't access service field for " + type + ": " + e.getMessage());
    } finally {
        serviceField.setAccessible(false);
    }
}
Also used : Field(java.lang.reflect.Field) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException)

Example 62 with HalException

use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.

the class ArtifactService method publishLatestSpinnaker.

public void publishLatestSpinnaker(String latestSpinnaker) {
    if (googleWriteableProfileRegistry == null) {
        throw new HalException(new ConfigProblemBuilder(FATAL, "You need to set the \"spinnaker.config.input.writerEnabled\" property to \"true\" to modify BOM contents.").build());
    }
    Versions versionsCollection = versionsService.getVersions();
    boolean hasLatest = versionsCollection.getVersions().stream().anyMatch(v -> v.getVersion().equals(latestSpinnaker));
    if (!hasLatest) {
        throw new HalException(FATAL, "Version " + latestSpinnaker + " does not exist in the list of published versions");
    }
    versionsCollection.setLatestSpinnaker(latestSpinnaker);
    googleWriteableProfileRegistry.writeVersions(yamlParser.dump(relaxedObjectMapper.convertValue(versionsCollection, Map.class)));
}
Also used : Versions(com.netflix.spinnaker.halyard.core.registry.v1.Versions) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException)

Example 63 with HalException

use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.

the class ArtifactService method publishLatestHalyard.

public void publishLatestHalyard(String latestHalyard) {
    if (googleWriteableProfileRegistry == null) {
        throw new HalException(new ConfigProblemBuilder(FATAL, "You need to set the \"spinnaker.config.input.writerEnabled\" property to \"true\" to modify BOM contents.").build());
    }
    Versions versionsCollection = versionsService.getVersions();
    versionsCollection.setLatestHalyard(latestHalyard);
    googleWriteableProfileRegistry.writeVersions(yamlParser.dump(relaxedObjectMapper.convertValue(versionsCollection, Map.class)));
}
Also used : Versions(com.netflix.spinnaker.halyard.core.registry.v1.Versions) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException)

Example 64 with HalException

use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.

the class ArtifactService method writeBom.

public void writeBom(String bomPath) {
    if (googleWriteableProfileRegistry == null) {
        throw new HalException(new ConfigProblemBuilder(FATAL, "You need to set the \"spinnaker.config.input.writerEnabled\" property to \"true\" to modify BOM contents.").build());
    }
    BillOfMaterials bom;
    String bomContents;
    String version;
    try {
        bomContents = IOUtils.toString(new FileInputStream(bomPath));
        bom = relaxedObjectMapper.convertValue(yamlParser.load(bomContents), BillOfMaterials.class);
        version = bom.getVersion();
    } catch (IOException e) {
        throw new HalException(new ConfigProblemBuilder(FATAL, "Unable to load Bill of Materials: " + e.getMessage()).build());
    }
    if (version == null) {
        throw new HalException(new ConfigProblemBuilder(FATAL, "No version was supplied in this BOM.").build());
    }
    googleWriteableProfileRegistry.writeBom(bom.getVersion(), bomContents);
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException) BillOfMaterials(com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials) FileInputStream(java.io.FileInputStream)

Example 65 with HalException

use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.

the class ArtifactService method deprecateVersion.

public void deprecateVersion(Version version, String illegalReason) {
    if (googleWriteableProfileRegistry == null) {
        throw new HalException(new ConfigProblemBuilder(FATAL, "You need to set the \"spinnaker.config.input.writerEnabled\" property to \"true\" to modify your halconfig bucket contents.").build());
    }
    Versions versionsCollection = versionsService.getVersions();
    deleteVersion(versionsCollection, version.getVersion());
    if (!StringUtils.isEmpty(illegalReason)) {
        List<Versions.IllegalVersion> illegalVersions = versionsCollection.getIllegalVersions();
        if (illegalVersions == null) {
            illegalVersions = new ArrayList<>();
        }
        illegalVersions.add(new Versions.IllegalVersion().setVersion(version.getVersion()).setReason(illegalReason));
        versionsCollection.setIllegalVersions(illegalVersions);
    }
    googleWriteableProfileRegistry.writeVersions(yamlParser.dump(relaxedObjectMapper.convertValue(versionsCollection, Map.class)));
}
Also used : Versions(com.netflix.spinnaker.halyard.core.registry.v1.Versions) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException)

Aggregations

HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)88 IOException (java.io.IOException)37 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)17 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)16 ArrayList (java.util.ArrayList)15 FileInputStream (java.io.FileInputStream)14 File (java.io.File)12 HashMap (java.util.HashMap)12 JobStatus (com.netflix.spinnaker.halyard.core.job.v1.JobStatus)11 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)11 Map (java.util.Map)11 JobRequest (com.netflix.spinnaker.halyard.core.job.v1.JobRequest)10 Field (java.lang.reflect.Field)9 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)8 Path (java.nio.file.Path)8 List (java.util.List)7 Compute (com.google.api.services.compute.Compute)6 Problem (com.netflix.spinnaker.halyard.core.problem.v1.Problem)6 Paths (java.nio.file.Paths)6 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)5