use of com.netflix.spinnaker.halyard.core.RemoteAction in project halyard by spinnaker.
the class AbstractRemoteActionCommand method runRemoteAction.
protected void runRemoteAction(OperationHandler<RemoteAction> operation) {
RemoteAction action = operation.get();
String scriptPath = action.getScriptPath();
if (StringUtils.isEmpty(scriptPath)) {
return;
}
boolean shouldRun;
if (autoRun == null) {
shouldRun = action.isAutoRun();
} else {
shouldRun = action.isAutoRun() && autoRun;
}
if (!shouldRun) {
AnsiStoryBuilder storyBuilder = new AnsiStoryBuilder();
AnsiParagraphBuilder paragraphBuilder = storyBuilder.addParagraph();
paragraphBuilder.addSnippet(action.getScriptDescription());
storyBuilder.addNewline();
paragraphBuilder = storyBuilder.addParagraph();
paragraphBuilder.addSnippet("Please run the following script:");
storyBuilder.addNewline();
paragraphBuilder = storyBuilder.addParagraph();
paragraphBuilder.addSnippet(action.getScriptPath()).addStyle(AnsiStyle.UNDERLINE);
AnsiUi.raw(storyBuilder.toString());
} else {
List<String> command = new ArrayList<>();
command.add(scriptPath);
JobRequest request = new JobRequest().setTokenizedCommand(command);
JobExecutor executor = getJobExecutor();
String jobId = executor.startJobFromStandardStreams(request);
JobStatus status = null;
try {
status = executor.backoffWait(jobId);
} catch (InterruptedException e) {
AnsiUi.failure("Interrupted.");
System.exit(1);
}
if (status.getResult() != JobStatus.Result.SUCCESS) {
AnsiUi.error("Error encountered running script. See above output for more details.");
System.exit(1);
}
}
}
use of com.netflix.spinnaker.halyard.core.RemoteAction in project halyard by spinnaker.
the class LocalGitDeckService method commitWrapperScripts.
@Override
public void commitWrapperScripts() {
Map<String, Object> bindings = new HashMap<>();
bindings.put("git-root", getGitRoot());
bindings.put("scripts-dir", getScriptsDir());
bindings.put("artifact", getArtifact().getName());
bindings.put("start-command", getStartCommand());
TemplatedResource scriptResource = new StringReplaceJarResource("/git/deck-start.sh");
scriptResource.setBindings(bindings);
String script = scriptResource.toString();
new RemoteAction().setScript(script).commitScript(Paths.get(getScriptsDir(), getArtifact().getName() + "-start.sh"));
scriptResource = new StringReplaceJarResource("/git/stop.sh");
scriptResource.setBindings(bindings);
script = scriptResource.toString();
new RemoteAction().setScript(script).commitScript(Paths.get(getScriptsDir(), getArtifact().getName() + "-stop.sh"));
}
use of com.netflix.spinnaker.halyard.core.RemoteAction in project halyard by spinnaker.
the class DistributedDeployer method connectCommand.
@Override
public RemoteAction connectCommand(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, SpinnakerRuntimeSettings runtimeSettings, List<SpinnakerService.Type> serviceTypes) {
RemoteAction result = new RemoteAction();
String connectCommands = String.join(" &\n", serviceTypes.stream().map(t -> serviceProvider.getDeployableService(t).connectCommand(deploymentDetails, runtimeSettings)).collect(Collectors.toList()));
result.setScript("#!/bin/bash\n" + connectCommands);
result.setScriptDescription("The generated script will open connections to the API & UI servers using ssh tunnels");
result.setAutoRun(false);
return result;
}
use of com.netflix.spinnaker.halyard.core.RemoteAction in project halyard by spinnaker.
the class LocalDeployer method deploy.
@Override
public RemoteAction deploy(LocalServiceProvider serviceProvider, DeploymentDetails deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, List<SpinnakerService.Type> serviceTypes) {
List<LocalService> enabledServices = serviceProvider.getLocalServices(serviceTypes).stream().filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled()).collect(Collectors.toList());
Map<String, String> installCommands = enabledServices.stream().filter(i -> !resolvedConfiguration.getServiceSettings(i.getService()).getSkipLifeCycleManagement()).reduce(new HashMap<>(), (commands, installable) -> {
String command = String.join("\n", installable.installArtifactCommand(deploymentDetails), installable.stageProfilesCommand(deploymentDetails, resolvedConfiguration));
commands.put(installable.getService().getCanonicalName(), command);
return commands;
}, (m1, m2) -> {
m1.putAll(m2);
return m1;
});
String installCommand = serviceProvider.getInstallCommand(deploymentDetails, resolvedConfiguration, installCommands);
RemoteAction result = new RemoteAction();
result.setAutoRun(true);
result.setScript(installCommand);
return result;
}
use of com.netflix.spinnaker.halyard.core.RemoteAction in project halyard by spinnaker.
the class DeployService method deploy.
public RemoteAction deploy(String deploymentName, List<DeployOption> deployOptions, List<String> serviceNames) {
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration);
List<SpinnakerService.Type> serviceTypes = serviceNames.stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList());
if (serviceTypes.isEmpty()) {
serviceTypes = serviceProvider.getServices().stream().map(SpinnakerService::getType).collect(Collectors.toList());
}
ResolvedConfiguration resolvedConfiguration;
if (deployOptions.contains(DeployOption.OMIT_CONFIG)) {
resolvedConfiguration = generateService.generateConfig(deploymentName, Collections.emptyList());
} else {
resolvedConfiguration = generateService.generateConfig(deploymentName, serviceTypes);
}
Path serviceSettingsPath = halconfigDirectoryStructure.getServiceSettingsPath(deploymentName);
configParser.atomicWrite(serviceSettingsPath, resolvedConfiguration.getRuntimeSettings());
Path serviceProfilesPath = halconfigDirectoryStructure.getServiceProfilesPath(deploymentName);
configParser.atomicWrite(serviceProfilesPath, resolvedConfiguration.getServiceProfiles());
Deployer deployer = getDeployer(deploymentConfiguration);
DeploymentDetails deploymentDetails = getDeploymentDetails(deploymentConfiguration);
RemoteAction action = deployer.deploy(serviceProvider, deploymentDetails, resolvedConfiguration, serviceTypes);
halconfigParser.backupConfig();
if (deployOptions.contains(DeployOption.FLUSH_INFRASTRUCTURE_CACHES)) {
deployer.flushInfrastructureCaches(serviceProvider, deploymentDetails, resolvedConfiguration.getRuntimeSettings());
}
if (!action.getScript().isEmpty()) {
action.commitScript(halconfigDirectoryStructure.getInstallScriptPath(deploymentName));
}
return action;
}
Aggregations