use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.
the class KubernetesV1DistributedService method connectToInstance.
@Override
default <S> S connectToInstance(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar, String instanceId) {
ServiceSettings settings = runtimeSettings.getServiceSettings(sidecar);
String namespace = getNamespace(settings);
int localPort = SocketUtils.findAvailableTcpPort();
int targetPort = settings.getPort();
List<String> command = KubernetesV1ProviderUtils.kubectlPortForwardCommand(details, namespace, instanceId, targetPort, localPort);
JobRequest request = new JobRequest().setTokenizedCommand(command);
String jobId = getJobExecutor().startJob(request);
// Wait for the proxy to spin up.
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
JobStatus status = getJobExecutor().updateJob(jobId);
// This should be a long-running job.
if (status.getState() == JobStatus.State.COMPLETED) {
throw new HalException(Problem.Severity.FATAL, "Unable to establish a proxy against " + getServiceName() + ":\n" + status.getStdOut() + "\n" + status.getStdErr());
}
return getServiceInterfaceFactory().createService(settings.getScheme() + "://localhost:" + localPort, sidecar);
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.
the class GenerateService method generateConfig.
/**
* Generate config for a given deployment.
*
* This involves a few steps:
*
* 1. Clear out old config generated in a prior run.
* 2. Generate configuration using the halconfig as the source of truth, while collecting files needed by
* the deployment.
*
* @param deploymentName is the deployment whose config to generate
* @param services is the list of services to generate configs for
* @return a mapping from components to the profile's required local files.
*/
public ResolvedConfiguration generateConfig(String deploymentName, List<SpinnakerService.Type> services) {
DaemonTaskHandler.newStage("Generating all Spinnaker profile files and endpoints");
log.info("Generating config from \"" + halconfigPath + "\" with deploymentName \"" + deploymentName + "\"");
File spinnakerStaging = halconfigDirectoryStructure.getStagingPath(deploymentName).toFile();
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
DaemonTaskHandler.message("Building service endpoints");
SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration);
SpinnakerRuntimeSettings runtimeSettings = serviceProvider.buildRuntimeSettings(deploymentConfiguration);
// Step 1.
try {
FileUtils.deleteDirectory(spinnakerStaging);
} catch (IOException e) {
throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Unable to clear old spinnaker config: " + e.getMessage() + ".").build());
}
Path userProfilePath = halconfigDirectoryStructure.getUserProfilePath(deploymentName);
List<String> userProfileNames = aggregateProfilesInPath(userProfilePath.toString(), "");
// Step 2.
Map<SpinnakerService.Type, Map<String, Profile>> serviceProfiles = new HashMap<>();
for (SpinnakerService service : serviceProvider.getServices()) {
boolean isDesiredService = services.stream().filter(s -> s.equals(service.getType())).count() > 0;
if (!isDesiredService) {
continue;
}
ServiceSettings settings = runtimeSettings.getServiceSettings(service);
if (settings == null || !settings.getEnabled()) {
continue;
}
List<Profile> profiles = service.getProfiles(deploymentConfiguration, runtimeSettings);
String pluralModifier = profiles.size() == 1 ? "" : "s";
String profileMessage = "Generated " + profiles.size() + " profile" + pluralModifier;
Map<String, Profile> outputProfiles = processProfiles(spinnakerStaging, profiles);
List<Profile> customProfiles = userProfileNames.stream().map(s -> (Optional<Profile>) service.customProfile(deploymentConfiguration, runtimeSettings, Paths.get(userProfilePath.toString(), s), s)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
pluralModifier = customProfiles.size() == 1 ? "" : "s";
profileMessage += " and discovered " + customProfiles.size() + " custom profile" + pluralModifier + " for " + service.getCanonicalName();
DaemonTaskHandler.message(profileMessage);
mergeProfilesAndPreserveProperties(outputProfiles, processProfiles(spinnakerStaging, customProfiles));
serviceProfiles.put(service.getType(), outputProfiles);
}
return new ResolvedConfiguration().setServiceProfiles(serviceProfiles).setRuntimeSettings(runtimeSettings);
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.
the class ConsulClientService method getSidecarProfiles.
@Override
public List<Profile> getSidecarProfiles(GenerateService.ResolvedConfiguration resolvedConfiguration, SpinnakerService service) {
List<Profile> result = new ArrayList<>();
Map<String, Profile> profiles = resolvedConfiguration.getProfilesForService(getType());
Profile profile = profiles.get(consulClientService(service.getCanonicalName()));
result.add(profile);
profile = profiles.get(clientProfileName);
result.add(profile);
return result;
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService in project halyard by spinnaker.
the class SpinnakerServiceProvider method buildRuntimeSettings.
public SpinnakerRuntimeSettings buildRuntimeSettings(DeploymentConfiguration deploymentConfiguration) {
SpinnakerRuntimeSettings endpoints = new SpinnakerRuntimeSettings();
for (SpinnakerService.Type type : SpinnakerService.Type.values()) {
SpinnakerService service = getSpinnakerService(type);
if (service != null) {
log.info("Building service settings entry for " + service.getServiceName());
ServiceSettings settings = service.getDefaultServiceSettings(deploymentConfiguration);
settings.mergePreferThis(service.buildServiceSettings(deploymentConfiguration));
endpoints.setServiceSettings(type, settings);
}
}
return endpoints;
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService 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);
}
}
Aggregations