@Override public DomainConnectorService get(String identifier) { resolveConfigConnectors(null); Registration registration = connectorsById.get(identifier); if (registration != null) return registration.service; return ServiceUtils.getService(DomainConnectorService.class, "id", identifier); }
@Override public Collection<DomainConnectorService> getConnectors() { resolveConfigConnectors(null); return ServiceUtils.getServices(DomainConnectorService.class); }
@Override public void doRun() { ArtifactStorageService storage = ServiceUtils.getService(ArtifactStorageService.class); if (storage == null) { result = XSPReplyServiceUnavailable.instance(); return; } result = storage.delete(artifactId); } }
/** * Responds to a request for the list of the connectors * * @return The response */ private HttpResponse onMessageListConnectors() { Collection<DomainConnectorService> connectors = ServiceUtils.getServices(DomainConnectorService.class); StringBuilder builder = new StringBuilder("["); boolean first = true; for (DomainConnectorService connector : connectors) { if (!first) builder.append(", "); first = false; builder.append(connector.serializedJSON()); } builder.append("]"); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, builder.toString()); }
/** * Pulls an artifact from a connector into the long-term store * * @param connectorId The identifier of a connector * @return The result of the operation */ public static XSPReply pullArtifactFrom(String connectorId) { DomainConnectorService connector = ServiceUtils.getService(DomainConnectorService.class, "id", connectorId); if (connector == null) return new XSPReplyFailure("Failed to resolve connector " + connectorId); return pullArtifactFrom(connector); }
return; Collection<JobFactory> factories = ServiceUtils.getServices(JobFactory.class); for (JobFactory factory : factories) { if (factory.canDeserialize(type)) {
/** * Responds to a request for a single connector * * @param connectorId The identifier of a connector * @return The response */ private HttpResponse onMessageGetConnector(String connectorId) { DomainConnectorService connector = ServiceUtils.getService(DomainConnectorService.class, "id", connectorId); if (connector == null) return new HttpResponse(HttpURLConnection.HTTP_NOT_FOUND); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, connector.serializedJSON()); }
/** * Pushes an artifact to a connector's client * * @param connectorId The identifier of the connector to push to * @param artifactId The identifier of the artifact to push * @return The result of the operation */ public static XSPReply pushArtifactTo(String connectorId, String artifactId) { DomainConnectorService connector = ServiceUtils.getService(DomainConnectorService.class, "id", connectorId); if (connector == null) return new XSPReplyFailure("Failed to resolve connector " + connectorId); ArtifactStorageService storage = ServiceUtils.getService(ArtifactStorageService.class); if (storage == null) return new XSPReplyFailure("Failed to resolve the artifact storage service"); XSPReply reply = storage.retrieve(artifactId); if (!reply.isSuccess()) return reply; return connector.pushToClient(((XSPReplyResult<Artifact>) reply).getData()); } }
ConfigurationService configurationService = ServiceUtils.getService(ConfigurationService.class); Configuration configuration = configurationService != null ? configurationService.getConfigFor(this) : null; int queueBound = EXECUTOR_QUEUE_BOUND;
isResolving = true; if (toResolve == null) { ConfigurationService configurationService = ServiceUtils.getService(ConfigurationService.class); if (configurationService == null) return;
@Override public void doRun() { ArtifactStorageService storage = ServiceUtils.getService(ArtifactStorageService.class); if (storage == null) { result = XSPReplyServiceUnavailable.instance(); return; } result = storage.retrieve(artifactId); if (!result.isSuccess()) return; result = storage.pushToLive(((XSPReplyResult<Artifact>) result).getData()); } }
/** * Responds to the request to pull an artifact from a connector * When successful, this action creates the appropriate job and returns it. * * @param parameters The request parameters * @return The response */ private HttpResponse onMessagePullFromConnector(Map<String, String[]> parameters) { String[] ids = parameters.get("id"); if (ids == null || ids.length == 0) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter"); JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class); if (executor == null) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Could not find the job execution service"); Job job = new PullArtifactJob(ids[0]); executor.schedule(job); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); }
@Override public void doRun() { ArtifactStorageService storage = ServiceUtils.getService(ArtifactStorageService.class); if (storage == null) { result = XSPReplyServiceUnavailable.instance(); return; } result = storage.retrieve(artifactId); if (!result.isSuccess()) return; result = storage.pullFromLive(((XSPReplyResult<Artifact>) result).getData()); } }
/** * Responds to the request to push an artifact to a connector * When successful, this action creates the appropriate job and returns it. * * @param parameters The request parameters * @return The response */ private HttpResponse onMessagePushToConnector(Map<String, String[]> parameters) { String[] ids = parameters.get("id"); if (ids == null || ids.length == 0) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter"); String[] artifacts = parameters.get("artifact"); if (artifacts == null || artifacts.length == 0) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an artifact parameter"); JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class); if (executor == null) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Could not find the job execution service"); Job job = new PushArtifactJob(ids[0], artifacts[0]); executor.schedule(job); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); } }
/** * Responds to a request to delete an artifact * * @param parameters The request parameters * @return The response */ private HttpResponse onMessageDeleteArtifact(Map<String, String[]> parameters) { String[] ids = parameters.get("id"); if (ids == null || ids.length == 0) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter"); JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class); if (executor == null) return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null); Job job = new DeleteArtifactJob(ids[0]); executor.schedule(job); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); }
/** * Responds to the request to pull an artifact from the live store * When successful, this action creates the appropriate job and returns it. * * @param parameters The request parameters * @return The response */ private HttpResponse onMessagePullFromLive(Map<String, String[]> parameters) { String[] ids = parameters.get("id"); if (ids == null || ids.length == 0) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter"); JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class); if (executor == null) return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null); Job job = new PullArtifactFromLiveJob(ids[0]); executor.schedule(job); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); }
/** * Responds to the request to push an artifact to the live store * When successful, this action creates the appropriate job and returns it. * * @param parameters The request parameters * @return The response */ private HttpResponse onMessagePushToLive(Map<String, String[]> parameters) { String[] ids = parameters.get("id"); if (ids == null || ids.length == 0) return new HttpResponse(HttpURLConnection.HTTP_BAD_REQUEST, HttpConstants.MIME_TEXT_PLAIN, "Expected an id parameter"); JobExecutionService executor = ServiceUtils.getService(JobExecutionService.class); if (executor == null) return XSPReplyUtils.toHttpResponse(XSPReplyServiceUnavailable.instance(), null); Job job = new PushArtifactToLiveJob(ids[0]); executor.schedule(job); return new HttpResponse(HttpURLConnection.HTTP_OK, HttpConstants.MIME_JSON, job.serializedJSON()); } }
/** * Pulls an artifact from the connector into the standard storage (usually the long-term store) * * @param connector The connector to pull from * @return The result of the operation */ public static XSPReply pullArtifactFrom(DomainConnectorService connector) { ArtifactStorageService storageService = ServiceUtils.getService(ArtifactStorageService.class); if (storageService == null) return new XSPReplyFailure("Failed to resolve an artifact storage service"); XSPReply replyArtifact = connector.getNextInput(false); if (!replyArtifact.isSuccess()) return replyArtifact; Artifact artifact = ((XSPReplyResult<Artifact>) replyArtifact).getData(); XSPReply reply = storageService.store(artifact); if (!reply.isSuccess()) return reply; // reply with the artifact return replyArtifact; }
/** * Resolves the remote for this store * * @param name The name of this store * @return The remote */ private XOWLDatabase resolveRemote(String name) { ConfigurationService configurationService = ServiceUtils.getService(ConfigurationService.class); if (configurationService == null) return null; Configuration configuration = configurationService.getConfigFor(this); if (configuration == null) return null; if (server == null) { String endpoint = configuration.get("endpoint"); if (endpoint == null) return null; server = new RemoteServer(endpoint); XSPReply reply = server.login(configuration.get("login"), configuration.get("password")); if (!reply.isSuccess()) return null; } String dbName = configuration.get(name); XSPReply reply = server.getDatabase(dbName); if (!reply.isSuccess()) return null; return ((XSPReplyResult<XOWLDatabase>) reply).getData(); }