use of org.platformlayer.ids.FederationKey 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.ids.FederationKey in project platformlayer by platformlayer.
the class PlatformLayerCliContext method pathToItem.
public PlatformLayerKey pathToItem(ProjectId project, String path) throws PlatformLayerClientException {
String serviceType = null;
String itemType = null;
String itemId = null;
if (path.contains("://")) {
return PlatformLayerKey.parse(path);
}
List<String> components = Lists.newArrayList(path.split("/"));
if (components.size() <= 1) {
throw new IllegalArgumentException("Cannot resolve path: " + path);
}
String head = components.get(0);
{
Map<String, ServiceInfo> services = listServices();
if (services.containsKey(head)) {
serviceType = services.get(head).serviceType;
components.remove(0);
if (components.size() <= 1) {
throw new IllegalArgumentException("Cannot resolve path: " + path);
}
head = components.get(0);
}
}
Multimap<String, ServiceInfo> items = listItemTypes();
if (items.containsKey(head)) {
Collection<ServiceInfo> services = items.get(head);
if (services.size() > 1) {
throw new IllegalArgumentException("Cannot resolve path (ambiguous item type): " + path);
}
ServiceInfo serviceInfo = Iterables.getOnlyElement(services);
itemType = head;
if (serviceType != null) {
if (!Objects.equal(serviceType, serviceInfo.serviceType)) {
throw new IllegalArgumentException("Cannot resolve path (service/item type mismatch): " + path);
}
} else {
serviceType = serviceInfo.serviceType;
}
components.remove(0);
} else {
throw new IllegalArgumentException("Cannot resolve path (unknown item type): " + path);
}
itemId = Joiner.on('/').join(components);
if (serviceType == null) {
throw new IllegalArgumentException("Cannot resolve path (service type not resolved): " + path);
}
if (itemType == null) {
throw new IllegalArgumentException("Cannot resolve path (item type not resolved): " + path);
}
if (Strings.isNullOrEmpty(itemId)) {
throw new IllegalArgumentException("Cannot resolve path (item id not resolved): " + path);
}
FederationKey host = null;
return new PlatformLayerKey(host, project, new ServiceType(serviceType), new ItemType(itemType), new ManagedItemId(itemId));
}
use of org.platformlayer.ids.FederationKey in project platformlayer by platformlayer.
the class PlatformLayerClientBase method toKey.
public static <T> PlatformLayerKey toKey(JaxbHelper jaxbHelper, ManagedItemId id, Class<T> itemClass, Collection<ServiceInfo> services) throws PlatformLayerClientException {
String namespaceURI = jaxbHelper.getPrimaryNamespace();
String nodeName = jaxbHelper.getXmlElementName();
if (namespaceURI == null) {
throw new IllegalArgumentException("Namespace could not be determined");
}
ServiceInfo service = getServiceInfo(services, namespaceURI);
if (service == null) {
throw new PlatformLayerClientException("Cannot find service for " + namespaceURI);
}
ServiceType serviceType = new ServiceType(service.getServiceType());
ItemType itemType = new ItemType(nodeName);
FederationKey host = null;
ProjectId project = null;
return new PlatformLayerKey(host, project, serviceType, itemType, id);
}
use of org.platformlayer.ids.FederationKey in project platformlayer by platformlayer.
the class PlatformLayerCommandRunnerBase method pathToKey.
public static PlatformLayerKey pathToKey(PlatformLayerClient client, String path) throws PlatformLayerClientException {
String serviceType;
String itemType;
if (path.contains("/")) {
String[] components = path.split("/");
if (components.length != 2) {
throw new IllegalArgumentException("Cannot parse path: " + path);
}
serviceType = components[0];
itemType = components[1];
} else {
itemType = path;
serviceType = getServiceTypeFromItemType(client, itemType);
}
FederationKey host = null;
ProjectId project = client.getProject();
return new PlatformLayerKey(host, project, new ServiceType(serviceType), new ItemType(itemType), null);
}
use of org.platformlayer.ids.FederationKey in project platformlayer by platformlayer.
the class FederationMap method toKey.
private FederationMapping toKey(PlatformLayerKey original, Rule rule) {
FederationKey targetHost = original.getHost();
ProjectId targetProject = original.getProject();
if (rule.targetKey != null) {
MappedTarget target = targetMap.get(rule.targetKey);
if (target == null) {
throw new IllegalStateException("Cannot find target: " + rule.targetKey);
}
targetHost = rule.targetKey.host;
targetProject = rule.targetKey.project;
}
return new FederationMapping(targetHost, targetProject);
}
Aggregations