use of com.netflix.spinnaker.halyard.config.model.v1.node.Account in project halyard by spinnaker.
the class AwsAddAccountCommand method buildAccount.
@Override
protected Account buildAccount(String accountName) {
AwsAccount account = (AwsAccount) new AwsAccount().setName(accountName);
account.setDefaultKeyPair(defaultKeyPair).setEdda(edda).setDiscovery(discovery).setAccountId(accountId).setRegions(regions.stream().map(r -> new AwsProvider.AwsRegion().setName(r)).collect(Collectors.toList())).setAssumeRole(assumeRole);
return account;
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Account in project halyard by spinnaker.
the class OracleBMCSAddAccountCommand method buildAccount.
@Override
protected Account buildAccount(String accountName) {
OracleBMCSAccount account = (OracleBMCSAccount) new OracleBMCSAccount().setName(accountName);
account.setCompartmentId(compartmentId);
account.setUserId(userId);
account.setFingerprint(fingerprint);
account.setSshPrivateKeyFilePath(sshPrivateKeyFilePath);
account.setTenancyId(tenancyId);
account.setRegion(region);
return account;
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Account in project halyard by spinnaker.
the class GoogleAddAccountCommand method buildAccount.
@Override
protected Account buildAccount(String accountName) {
GoogleAccount account = (GoogleAccount) new GoogleAccount().setName(accountName);
account = (GoogleAccount) account.setJsonPath(jsonPath).setProject(project);
account.setAlphaListed(alphaListed).setImageProjects(imageProjects).setUserDataFile(userDataFile).setRegions(regions);
return account;
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Account 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>>() { });
*/
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Account 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));
}
}
Aggregations