use of org.platformlayer.TypedPlatformLayerClient in project platformlayer by platformlayer.
the class OpsContextBuilder method buildClient.
private TypedPlatformLayerClient buildClient(ProjectAuthorization project) throws OpsException {
ProjectId projectId = new ProjectId(project.getName());
DirectAuthenticator directAuthenticator = buildDirectAuthenticator(project);
// TODO: Introduce a direct client for "loopback" (normal) calls?
String platformLayerUrl = OpsSystem.getPlatformLayerUrlBase();
List<String> trustKeys = opsSystem.getServerTrustKeys();
PlatformLayerClient client;
// client = HttpPlatformLayerClient.build(httpStrategy, platformLayerUrl,
// directAuthenticator, projectId, trustKeys);
DirectAuthentication auth = new DirectAuthentication(project);
TypedItemMapper mapper = null;
client = new DirectPlatformLayerClient(mapper, opsSystem, projectId, auth);
return new PlatformLayerHelpers(client, serviceProviderHelpers);
}
use of org.platformlayer.TypedPlatformLayerClient 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.TypedPlatformLayerClient in project platformlayer by platformlayer.
the class PlatformLayerTestContext method getItem.
public <T extends ItemBase> T getItem(String id, Class<T> itemClass) throws OpsException, IOException {
TypedPlatformLayerClient client = getTypedClient();
JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(itemClass, new Class[] {});
PlatformLayerKey key = PlatformLayerClientBase.toKey(jaxbHelper, new ManagedItemId(id), itemClass, client.listServices(true));
return client.getItem(key, itemClass);
}
use of org.platformlayer.TypedPlatformLayerClient in project platformlayer by platformlayer.
the class FederatedPlatformLayerClient method buildClients.
// public static FederatedPlatformLayerClient buildUsingSavedConfiguration(String key) throws IOException {
// File credentialsFile = new File(System.getProperty("user.home") + File.separator + ".credentials" +
// File.separator + key);
// if (!credentialsFile.exists())
// throw new FileNotFoundException("Configuration file not found: " + credentialsFile);
// Properties properties = new Properties();
// try {
// properties.load(new FileInputStream(credentialsFile));
// } catch (IOException e) {
// throw new IOException("Error reading configuration file: " + credentialsFile, e);
// }
// return buildUsingProperties(properties);
// }
// public static FederatedPlatformLayerClient buildUsingConfig(InputStream is, TypedItemMapper mapper)
// throws OpsException {
// FederationConfiguration federationMapConfig = SmartDeserialization.deserialize(FederationConfiguration.class,
// is);
// FederationMap federationMap = new FederationMap(mapper, federationMapConfig);
//
// // int parallelism = Runtime.getRuntime().availableProcessors();
// // // Because we're doing lots of HTTP requests, rather than being CPU bound, we massively increase the
// // parallelism
// // parallelism *= 256;
//
// ForkJoinStrategy forkJoinPool = new FakeForkJoinStrategy();
//
// return new FederatedPlatformLayerClient(federationMap, forkJoinPool);
// }
void buildClients() {
for (FederationMapping key : federationMap.getAllTargetKeys()) {
TypedPlatformLayerClient client = federationMap.buildClient(key);
ChildClient child = new ChildClient(key, client);
childClients.put(key, child);
}
if (childClients.isEmpty()) {
throw new IllegalStateException();
}
}
Aggregations