use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class OpsContextBuilder method buildOpsContext.
public OpsContext buildOpsContext(ActiveJobExecution activeJob) throws OpsException {
ServiceType serviceType = activeJob.getServiceType();
ProjectAuthorization projectAuthz = activeJob.getProjectAuthorization();
List<ProjectAuthorization> projects = Lists.newArrayList();
// .getProject();
ProjectAuthorization runAsProject = projectAuthz;
projects.add(runAsProject);
MultitenantConfiguration multitenant = opsSystem.getMultitenantConfiguration();
if (multitenant != null) {
ProjectAuthorization masterProject = multitenant.getMasterProject();
if (runAsProject.getName().equals(masterProject.getName())) {
// We're in the master project
multitenant = null;
} else {
runAsProject = masterProject;
projects.add(runAsProject);
}
}
TypedPlatformLayerClient defaultClient = buildClient(runAsProject);
FederationConfiguration federationMapConfig = FederatedPlatformLayerClient.buildFederationConfiguration(defaultClient);
FederationMap federationMap = new FederationMap(httpStrategy, mapper, federationMapConfig);
if (multitenant != null) {
// .getProject();
ProjectAuthorization localProject = projectAuthz;
TypedPlatformLayerClient localClient = buildClient(localProject);
FederationKey host = FederationKey.LOCAL;
ProjectId project = localClient.getProject();
FederationMapping mapKey = new FederationMapping(host, project);
federationMap.addMapping(mapKey, localClient);
for (PlatformLayerKey mappedService : multitenant.getMappedItems()) {
FederationMap.Rule rule = new FederationMap.Rule();
rule.mappedItems = mappedService;
rule.targetKey = mapKey;
federationMap.addRule(rule);
}
}
ProjectId runAsProjectId = new ProjectId(runAsProject.getName());
PlatformLayerClient platformLayerClient;
if (federationMap.isEmpty()) {
platformLayerClient = defaultClient;
} else {
federationMap.addDefault(defaultClient);
platformLayerClient = FederatedPlatformLayerClient.build(runAsProjectId, federationMap);
}
ServiceConfiguration serviceConfiguration = new ServiceConfiguration(runAsProjectId, serviceType);
ServiceAuthorization serviceAuthorization;
try {
serviceAuthorization = serviceAuthorizationService.findServiceAuthorization(serviceType, runAsProjectId);
// }
if (serviceAuthorization == null) {
serviceAuthorization = new ServiceAuthorization();
serviceAuthorization.serviceType = serviceConfiguration.getServiceType().getKey();
}
} catch (RepositoryException e) {
throw new OpsException("Error reading from repository", e);
}
// OpsConfig opsConfig = OpsConfig.build(serviceAuthorization);
// UserInfo userInfo = new SimpleUserInfo(auth, opsConfig);
OpsContext opsContext = new OpsContext(opsSystem, activeJob, serviceConfiguration, platformLayerClient, projects);
return opsContext;
}
use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class SchedulerImpl method toRunnable.
private Runnable toRunnable(final ActionTask task) {
final PlatformLayerKey target = task.target;
final PlatformLayerEndpointInfo endpoint = rehydrateEndpoint(task.endpoint);
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
PlatformLayerClient platformLayer = HttpPlatformLayerClient.build(httpStrategy, endpoint.getPlatformlayerBaseUrl(), endpoint.getAuthenticator(), endpoint.getProjectId(), endpoint.getTrustKeys());
platformLayer.doAction(target, task.action);
// TODO: Wait for task completion??
// TODO: Link job id??
} catch (PlatformLayerClientException e) {
log.warn("Error running action", e);
}
}
@Override
public String toString() {
return task.action + " on " + task.target;
}
};
return runnable;
}
use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class StandardTemplateData method findPublicSslKey.
public ManagedSecretKey findPublicSslKey() throws OpsException {
PlatformLayerKey sslKey = getSslKeyPath();
if (sslKey == null) {
if (getCaPath() != null) {
ManagedSecretKey key = findCaSignedKey("public");
if (key != null) {
return key;
}
}
return null;
}
ItemBase sslKeyItem = (ItemBase) platformLayer.getItem(sslKey);
ManagedSecretKey key = providers.toInterface(sslKeyItem, ManagedSecretKey.class);
return key;
}
use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class OwnedEndpoint method buildItemTemplate.
@Override
protected PublicEndpointBase buildItemTemplate() throws OpsException {
InstanceBase instance = OpsContext.get().getInstance(InstanceBase.class);
PlatformLayerKey instanceKey = instance.getKey();
PublicEndpointBase publicEndpoint = platformLayerCloudHelpers.createPublicEndpoint(instance, parentItem);
// publicEndpoint.network = network;
publicEndpoint.publicPort = publicPort;
publicEndpoint.publicPortCluster = publicPortCluster;
publicEndpoint.backendPort = backendPort;
publicEndpoint.instance = instanceKey;
publicEndpoint.key = PlatformLayerKey.fromId(instance.getId() + "_" + publicPort);
if (transport != null) {
publicEndpoint.transport = transport.toString();
}
// publicEndpoint.getTags().add(OpsSystem.get().createParentTag(instance));
Tag uniqueTag = UniqueTag.build(instance, String.valueOf(publicPort));
publicEndpoint.getTags().add(uniqueTag);
return publicEndpoint;
}
use of org.platformlayer.core.model.PlatformLayerKey in project platformlayer by platformlayer.
the class ForEach method doRecursion.
public void doRecursion(Object controller, SshKey sshKey, Class<? extends ItemBase> machineItemClass, Class<? extends ItemBase> dataItemClass) throws OpsException {
boolean failed = false;
OpsContext ops = OpsContext.get();
List<ItemBase> dataItems = Lists.newArrayList();
ItemBase contextDataItem = ops.getInstance(dataItemClass);
if (contextDataItem != null) {
dataItems.add(contextDataItem);
} else {
for (ItemBase dataItem : platformLayer.listItems(dataItemClass)) {
dataItems.add(dataItem);
}
}
Object contextMachine = ops.getInstance(machineItemClass);
if (contextMachine != null) {
// We are presumably building the machine item
PlatformLayerKey targetItemKey = ops.getJobRecord().getTargetItemKey();
ItemBase machineItem = (ItemBase) contextMachine;
if (!Objects.equal(targetItemKey, machineItem.getKey())) {
throw new OpsException("Expected to find same model");
}
Machine machine = instances.findMachine(machineItem);
if (machine == null) {
log.warn("Server instance not found: " + contextMachine);
failed = true;
} else {
OpsTarget target = machine.getTarget(sshKey);
failed |= processDataItems(controller, dataItems, machineItem, machine, target);
}
} else {
// We are building a data item
for (ItemBase machineItem : platformLayer.listItems(machineItemClass)) {
if (machineItem.getState() != ManagedItemState.ACTIVE) {
log.warn("Machine not yet active: " + machineItem);
failed = true;
continue;
}
Machine machine = instances.findMachine(machineItem);
if (machine == null) {
log.warn("Server instance not found: " + machineItem);
failed = true;
continue;
}
OpsTarget target = machine.getTarget(sshKey);
failed |= processDataItems(controller, dataItems, machineItem, machine, target);
}
}
if (failed) {
throw new OpsException("Could not update all servers").setRetry(TimeSpan.ONE_MINUTE);
}
}
Aggregations