use of org.platformlayer.ids.ServiceType 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.ServiceType 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.ServiceType in project platformlayer by platformlayer.
the class ProviderHelper method findModelsProviding.
private List<ModelClass<?>> findModelsProviding(Class<?> serviceClass) throws OpsException {
List<ModelClass<?>> models = Lists.newArrayList();
for (ServiceInfo service : serviceProviderDictionary.getAllServices()) {
ServiceType serviceType = new ServiceType(service.getServiceType());
ServiceProvider serviceProvider = serviceProviderDictionary.getServiceProvider(serviceType);
for (ModelClass<?> model : serviceProvider.getModels().all()) {
Class<?> controllerClass = serviceProvider.getControllerClass(model.getJavaClass());
if (serviceClass.isAssignableFrom(controllerClass)) {
models.add(model);
}
}
}
return models;
}
use of org.platformlayer.ids.ServiceType in project platformlayer by platformlayer.
the class ImageStoreController method getImageStore.
@Override
public org.platformlayer.ops.images.ImageStore getImageStore() throws OpsException {
String endpoint = model.getTags().findUnique("endpoint");
if (endpoint == null) {
log.warn("ImageStore not yet active: " + model);
return null;
}
URI url;
try {
url = new URI(endpoint);
} catch (URISyntaxException e) {
throw new OpsException("Cannot parse endpoint: " + endpoint, e);
}
if (url.getScheme().equals("ssh")) {
String myAddress = url.getHost();
Machine machine = new OpaqueMachine(NetworkPoint.forPublicHostname(myAddress));
// This is nasty; we're in the context of another service here...
SshKey sshKey = sshKeys.findOtherServiceKey(new ServiceType("imagestore"));
OpsTarget target = machine.getTarget("imagestore", sshKey.getKeyPair());
DirectImageStore directImageStore = OpsContext.get().getInjector().getInstance(DirectImageStore.class);
directImageStore.connect(target);
return directImageStore;
} else {
throw new OpsException("Unknown protocol for endpoint: " + endpoint);
}
}
use of org.platformlayer.ids.ServiceType in project platformlayer by platformlayer.
the class JdbcManagedItemRepository method getManagedItem.
@Override
@JdbcTransaction
public ItemBase getManagedItem(PlatformLayerKey key, boolean fetchTags, SecretProvider secretProvider) throws RepositoryException {
DbHelper db = new DbHelper(key);
try {
ServiceProvider serviceProvider = serviceProviderDirectory.getServiceProvider(key.getServiceType());
if (serviceProvider == null) {
throw new IllegalStateException();
}
ModelClass<?> modelClass = serviceProvider.getModelClass(key.getItemType());
ServiceType serviceType = key.getServiceType();
ItemType itemType = key.getItemType();
ProjectId project = key.getProject();
ManagedItemId itemId = key.getItemId();
return fetchItem(db, serviceType, itemType, project, itemId, modelClass.getJavaClass(), secretProvider, fetchTags);
} catch (SQLException e) {
throw new RepositoryException("Error running query", e);
} finally {
db.close();
}
}
Aggregations