use of com.netflix.spinnaker.halyard.core.error.v1.HalException 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);
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException 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);
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class GoogleDistributedService method ensureRunning.
@Override
default void ensureRunning(AccountDeploymentDetails<GoogleAccount> details, ResolvedConfiguration resolvedConfiguration, List<ConfigSource> configSources, boolean recreate) {
DaemonTaskHandler.newStage("Deploying " + getServiceName() + " via GCE API");
Integer version = 0;
ServiceSettings settings = resolvedConfiguration.getServiceSettings(getService());
SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
RunningServiceDetails runningServiceDetails = getRunningServiceDetails(details, runtimeSettings);
GoogleAccount account = details.getAccount();
Compute compute = GoogleProviderUtils.getCompute(details);
String project = account.getProject();
String zone = settings.getLocation();
boolean exists = runningServiceDetails.getInstances().containsKey(version);
if (!recreate && exists) {
DaemonTaskHandler.message("Service " + getServiceName() + " is already deployed and not safe to restart");
return;
} else if (exists) {
DaemonTaskHandler.message("Recreating existing " + getServiceName() + "...");
deleteVersion(details, settings, version);
}
InstanceGroupManager manager = new InstanceGroupManager();
InstanceTemplate template = new InstanceTemplate().setName(getServiceName() + "-hal-" + System.currentTimeMillis()).setDescription("Halyard-generated instance template for deploying Spinnaker");
Metadata metadata = new Metadata().setItems(getMetadata(details, runtimeSettings, configSources, version));
AccessConfig accessConfig = new AccessConfig().setName("External NAT").setType("ONE_TO_ONE_NAT");
NetworkInterface networkInterface = new NetworkInterface().setNetwork(GoogleProviderUtils.ensureSpinnakerNetworkExists(details)).setAccessConfigs(Collections.singletonList(accessConfig));
ServiceAccount sa = new ServiceAccount().setEmail(GoogleProviderUtils.defaultServiceAccount(details)).setScopes(getScopes());
InstanceProperties properties = new InstanceProperties().setMachineType(getDefaultInstanceType()).setMetadata(metadata).setServiceAccounts(Collections.singletonList(sa)).setNetworkInterfaces(Collections.singletonList(networkInterface));
AttachedDisk disk = new AttachedDisk().setBoot(true).setAutoDelete(true).setType("PERSISTENT");
AttachedDiskInitializeParams diskParams = new AttachedDiskInitializeParams().setDiskSizeGb(20L).setDiskStorageType(GCEUtil.buildDiskTypeUrl(project, zone, GoogleDiskType.PD_SSD)).setSourceImage(getArtifactId(details.getDeploymentName()));
disk.setInitializeParams(diskParams);
List<AttachedDisk> disks = new ArrayList<>();
disks.add(disk);
properties.setDisks(disks);
template.setProperties(properties);
String instanceTemplateUrl;
Operation operation;
try {
DaemonTaskHandler.message("Creating an instance template");
operation = compute.instanceTemplates().insert(project, template).execute();
instanceTemplateUrl = operation.getTargetLink();
GoogleProviderUtils.waitOnGlobalOperation(compute, project, operation);
} catch (IOException e) {
throw new HalException(FATAL, "Failed to create instance template for " + settings.getArtifactId() + ": " + e.getMessage(), e);
}
String migName = getVersionedName(version);
manager.setInstanceTemplate(instanceTemplateUrl);
manager.setBaseInstanceName(migName);
manager.setTargetSize(settings.getTargetSize());
manager.setName(migName);
try {
DaemonTaskHandler.message("Deploying the instance group manager");
operation = compute.instanceGroupManagers().insert(project, settings.getLocation(), manager).execute();
GoogleProviderUtils.waitOnZoneOperation(compute, project, settings.getLocation(), operation);
} catch (IOException e) {
throw new HalException(FATAL, "Failed to create instance group to run artifact " + settings.getArtifactId() + ": " + e.getMessage(), e);
}
boolean ready = false;
DaemonTaskHandler.message("Waiting for all instances to become healthy.");
while (!ready) {
ready = getRunningServiceDetails(details, runtimeSettings).getLatestEnabledVersion() == version;
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(2));
}
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class VaultConfigMount method fromLocalFile.
public static VaultConfigMount fromLocalFile(File localFile, String desiredPath) {
String contents;
try {
String unencodedContents = IOUtils.toString(new FileInputStream(localFile));
contents = Base64.getEncoder().encodeToString(unencodedContents.getBytes());
} catch (IOException e) {
throw new HalException(Problem.Severity.FATAL, "Failed to read local config file: " + localFile, e);
}
return new VaultConfigMount().setContents(contents).setFile(desiredPath);
}
use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.
the class DeployService method getDeploymentDetails.
private DeploymentDetails getDeploymentDetails(DeploymentConfiguration deploymentConfiguration) {
String deploymentName = deploymentConfiguration.getName();
BillOfMaterials billOfMaterials = artifactService.getBillOfMaterials(deploymentName);
DeploymentEnvironment.DeploymentType type = deploymentConfiguration.getDeploymentEnvironment().getType();
switch(type) {
case BakeDebian:
case LocalDebian:
case LocalGit:
return new DeploymentDetails().setDeploymentConfiguration(deploymentConfiguration).setDeploymentName(deploymentName).setBillOfMaterials(billOfMaterials);
case Distributed:
DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment();
String accountName = deploymentEnvironment.getAccountName();
if (accountName == null || accountName.isEmpty()) {
throw new HalException(FATAL, "An account name must be " + "specified as the desired place to deploy your simple clustered deployment.");
}
Account account = accountService.getAnyProviderAccount(deploymentConfiguration.getName(), accountName);
return new AccountDeploymentDetails().setAccount(account).setDeploymentConfiguration(deploymentConfiguration).setDeploymentName(deploymentName).setBillOfMaterials(billOfMaterials);
default:
throw new IllegalArgumentException("Unrecognized deployment type " + type);
}
}
Aggregations