Search in sources :

Example 21 with SpinnakerRuntimeSettings

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.

the class DistributedService method buildRollbackPipeline.

default Map<String, Object> buildRollbackPipeline(AccountDeploymentDetails<A> details, SpinnakerRuntimeSettings runtimeSettings) {
    RunningServiceDetails serviceDetails = getRunningServiceDetails(details, runtimeSettings);
    Integer version = serviceDetails.getLatestEnabledVersion();
    if (version == null) {
        throw new HalException(Problem.Severity.FATAL, "There are no enabled server groups for service " + getServiceName() + " nothing to rollback to.");
    }
    int targetSize = serviceDetails.getInstances().get(version).size();
    targetSize = targetSize == 0 ? 1 : targetSize;
    ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
    Map<String, Object> baseDescription = new HashMap<>();
    baseDescription.put("cloudProvider", getProviderType().getId());
    baseDescription.put("cloudProviderType", getProviderType().getId());
    baseDescription.put("region", getRegion(settings));
    baseDescription.put("credentials", details.getAccount().getName());
    baseDescription.put("cluster", getServiceName());
    baseDescription.put("name", "rollback");
    Map<String, Object> capacity = new HashMap<>();
    capacity.put("desired", targetSize);
    Map<String, Object> resizeDescription = new HashMap<>();
    resizeDescription.putAll(baseDescription);
    String resizeId = "resize";
    resizeDescription.put("name", "Resize old " + getServiceName() + " to prior size");
    resizeDescription.put("capacity", capacity);
    resizeDescription.put("type", "resizeServerGroup");
    resizeDescription.put("refId", resizeId);
    resizeDescription.put("target", "ancestor_asg_dynamic");
    resizeDescription.put("action", "scale_exact");
    resizeDescription.put("requisiteStageRefIds", Collections.emptyList());
    Map<String, Object> enableDescription = new HashMap<>();
    enableDescription.putAll(baseDescription);
    String enableId = "enable";
    enableDescription.put("name", "Enable old " + getServiceName());
    enableDescription.put("type", "enableServerGroup");
    enableDescription.put("refId", enableId);
    enableDescription.put("target", "ancestor_asg_dynamic");
    enableDescription.put("requisiteStageRefIds", Collections.singletonList(resizeId));
    // This is a destroy, rather than a disable because the typical flow will look like this:
    // 
    // 1. You deploy a new version/config
    // 2. Something is wrong, so you rollback.
    // 3. Fixing the bad server group requires redeploying.
    // 
    // Since you can't fix the newest destroyed server group in place, and you won't (at least I can't imagine why)
    // want to reenable that server group, there is no point it keeping it around. There's an argument
    // to be made for keeping it around to debug, but that's far from what the average halyard user will want
    // to do.
    Map<String, Object> destroyDescription = new HashMap<>();
    String destroyId = "destroy";
    destroyDescription.putAll(baseDescription);
    destroyDescription.put("name", "Destroy current " + getServiceName());
    destroyDescription.put("type", "destroyServerGroup");
    destroyDescription.put("refId", destroyId);
    destroyDescription.put("requisiteStageRefIds", Collections.singletonList(enableId));
    destroyDescription.put("target", "current_asg_dynamic");
    List<Map<String, Object>> stages = new ArrayList<>();
    stages.add(resizeDescription);
    stages.add(enableDescription);
    stages.add(destroyDescription);
    Map<String, Object> pipeline = new HashMap<>();
    pipeline.put("stages", stages);
    pipeline.put("application", "spin");
    pipeline.put("name", "Rollback " + getServiceName());
    pipeline.put("description", "Auto-generated by Halyard");
    return pipeline;
}
Also used : HashMap(java.util.HashMap) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with SpinnakerRuntimeSettings

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.

the class GoogleDistributedService method buildConnectionDetails.

default VaultConnectionDetails buildConnectionDetails(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, String secretName) {
    GoogleVaultServerService vaultService = getVaultServerService();
    VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
    ServiceSettings vaultSettings = runtimeSettings.getServiceSettings(vaultService);
    RunningServiceDetails vaultDetails = vaultService.getRunningServiceDetails(details, runtimeSettings);
    Integer latestVaultVersion = vaultDetails.getLatestEnabledVersion();
    if (latestVaultVersion == null) {
        throw new IllegalStateException("No vault services have been started yet. This is a bug.");
    }
    List<RunningServiceDetails.Instance> instances = vaultDetails.getInstances().get(latestVaultVersion);
    if (instances.isEmpty()) {
        throw new IllegalStateException("Current vault service has no running instances. This is a bug.");
    }
    String instanceId = instances.get(0).getId();
    String address = new URIBuilder().setScheme("http").setHost(instanceId).setPort(vaultSettings.getPort()).toString();
    String token = vaultService.getToken(details.getDeploymentName(), vault);
    return new VaultConnectionDetails().setAddress(address).setSecret(secretName).setToken(token);
}
Also used : VaultConnectionDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails) ManagedInstance(com.google.api.services.compute.model.ManagedInstance) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) VaultServerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 23 with SpinnakerRuntimeSettings

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.

the class GoogleDistributedService method getServerGroupDescription.

@Override
default Map<String, Object> getServerGroupDescription(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, List<ConfigSource> configSources) {
    GoogleAccount account = details.getAccount();
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    Integer version = runningServiceDetails.getLatestEnabledVersion();
    if (version == null) {
        version = 0;
    } else {
        version++;
    }
    Names name = Names.parseName(getServiceName());
    String app = name.getApp();
    String stack = name.getStack();
    String detail = name.getDetail();
    String network = GoogleProviderUtils.getNetworkName();
    Map<String, String> metadata = getMetadata(details, runtimeSettings, configSources, version).stream().reduce(new HashMap<String, String>(), (h1, item) -> {
        h1.put(item.getKey(), item.getValue());
        return h1;
    }, (h1, h2) -> {
        h1.putAll(h2);
        return h1;
    });
    String serviceAccountEmail = GoogleProviderUtils.defaultServiceAccount(details);
    List<String> scopes = getScopes();
    String accountName = account.getName();
    Map<String, Object> deployDescription = new HashMap<>();
    deployDescription.put("application", app);
    deployDescription.put("stack", stack);
    deployDescription.put("freeFormDetails", detail);
    deployDescription.put("network", network);
    deployDescription.put("instanceMetadata", metadata);
    deployDescription.put("serviceAccountEmail", serviceAccountEmail);
    deployDescription.put("authScopes", scopes);
    deployDescription.put("accountName", accountName);
    deployDescription.put("account", accountName);
    return deployDescription;
/* TODO(lwander): Google's credential class cannot be serialized as-is, making this type of construction impossible
    BasicGoogleDeployDescription deployDescription = new BasicGoogleDeployDescription();
    deployDescription.setApplication(app);
    deployDescription.setStack(stack);
    deployDescription.setFreeFormDetails(detail);

    deployDescription.setNetwork(network);
    deployDescription.setInstanceMetadata(metadata);
    deployDescription.setServiceAccountEmail(serviceAccountEmail);
    deployDescription.setAuthScopes(scopes);
    // Google's credentials constructor prevents us from neatly creating a deploy description with only a name supplied
    String jsonKey = null;
    if (!StringUtils.isEmpty(account.getJsonPath())) {
      try {
        jsonKey = IOUtils.toString(new FileInputStream(account.getJsonPath()));
      } catch (IOException e) {
        throw new RuntimeException("Unvalidated json path found during deployment: " + e.getMessage(), e);
      }
    }

    deployDescription.setCredentials(new GoogleNamedAccountCredentials.Builder()
        .name(account.getName())
        .jsonKey(jsonKey)
        .project(account.getProject())
        .build()
    );

    return new ObjectMapper().convertValue(deployDescription, new TypeReference<Map<String, Object>>() { });
    */
}
Also used : Names(com.netflix.frigga.Names) GoogleAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleAccount) HashMap(java.util.HashMap) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)

Example 24 with SpinnakerRuntimeSettings

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.

the class GoogleDistributedService method sshTunnelIntoService.

default <S> URI sshTunnelIntoService(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar) {
    ServiceSettings settings = runtimeSettings.getServiceSettings(sidecar);
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    Integer enabledVersion = runningServiceDetails.getLatestEnabledVersion();
    if (enabledVersion == null) {
        throw new HalException(FATAL, "Cannot connect to " + getServiceName() + " when no server groups have been deployed yet");
    }
    List<RunningServiceDetails.Instance> instances = runningServiceDetails.getInstances().get(enabledVersion);
    if (instances == null || instances.isEmpty()) {
        throw new HalException(FATAL, "Cannot connect to " + getServiceName() + " when no instances have been deployed yet");
    }
    try {
        return GoogleProviderUtils.openSshTunnel(details, instances.get(0).getId(), settings);
    } catch (InterruptedException e) {
        throw new DaemonTaskInterrupted(e);
    }
}
Also used : ManagedInstance(com.google.api.services.compute.model.ManagedInstance) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) DaemonTaskInterrupted(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskInterrupted)

Example 25 with SpinnakerRuntimeSettings

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.

the class GoogleDistributedService method connectCommand.

@Override
default String connectCommand(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
    RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
    Integer version = runningServiceDetails.getLatestEnabledVersion();
    if (version == null) {
        throw new HalException(FATAL, "No version of " + getServiceName() + " to connect to.");
    }
    List<RunningServiceDetails.Instance> instances = runningServiceDetails.getInstances().get(version);
    if (instances.isEmpty()) {
        throw new HalException(FATAL, "Version " + version + " of " + getServiceName() + " has no instances to connect to");
    }
    RunningServiceDetails.Instance instance = instances.get(0);
    String instanceName = instance.getId();
    String zone = instance.getLocation();
    ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
    int port = settings.getPort();
    return String.format("gcloud compute ssh %s --zone %s -- -L %d:localhost:%d -N", instanceName, zone, port, port);
}
Also used : ManagedInstance(com.google.api.services.compute.model.ManagedInstance) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)

Aggregations

ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)28 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)22 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)20 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)20 ArrayList (java.util.ArrayList)20 Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)19 HashMap (java.util.HashMap)16 SpinnakerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)15 Map (java.util.Map)12 List (java.util.List)11 AccountDeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails)9 Collectors (java.util.stream.Collectors)9 Names (com.netflix.frigga.Names)7 RemoteAction (com.netflix.spinnaker.halyard.core.RemoteAction)7 DistributedService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService)7 HashSet (java.util.HashSet)7 Problem (com.netflix.spinnaker.halyard.core.problem.v1.Problem)6 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)6 Collections (java.util.Collections)6 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)5