use of org.platformlayer.federation.model.FederationConfiguration 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.federation.model.FederationConfiguration in project platformlayer by platformlayer.
the class FederatedPlatformLayerClient method buildFederationConfiguration.
// public static FederationMap buildFederationMap(HttpStrategy httpStrategy, TypedPlatformLayerClient localClient,
// TypedItemMapper mapper) throws OpsException {
// FederationConfiguration federationMapConfig = buildFederationConfiguration(localClient);
//
// FederationMap federationMap = new FederationMap(httpStrategy, mapper, federationMapConfig);
//
// if (localClient != null) {
// federationMap.addDefault(localClient);
// }
//
// return federationMap;
// }
public static FederationConfiguration buildFederationConfiguration(TypedPlatformLayerClient localClient) throws OpsException {
FederationConfiguration federationMapConfig = new FederationConfiguration();
String federationNamespace = "http://platformlayer.org/service/federation/v1.0";
boolean federationEnabled = isServiceEnabled(localClient, federationNamespace);
if (federationEnabled) {
for (FederatedService service : localClient.listItems(FederatedService.class)) {
PlatformLayerConnectionConfiguration config = new PlatformLayerConnectionConfiguration();
config.key = service.getKey();
config.secret = service.getSecret();
config.authenticationEndpoint = service.getServer();
config.tenant = service.getTenant();
config.username = service.getUsername();
config.platformlayerEndpoint = service.getServer();
federationMapConfig.systems.add(config);
}
for (FederatedServiceMap map : localClient.listItems(FederatedServiceMap.class)) {
FederationRule rule = new FederationRule();
rule.target = map.getTarget();
rule.serviceType = map.getServiceType();
federationMapConfig.rules.add(rule);
}
}
return federationMapConfig;
}
Aggregations