Search in sources :

Example 6 with Instance

use of com.ibm.streamsx.rest.Instance in project streamsx.topology by IBMStreams.

the class RemoteDistributedStreamsContext method setSubmissionInstance.

static void setSubmissionInstance(AppEntity entity) throws IOException {
    Instance cfgInstance = getConfigInstance(entity);
    if (cfgInstance != null) {
        StreamsConnection sc = cfgInstance.getStreamsConnection();
        boolean verify = cfgInstance.getStreamsConnection().isVerify();
        JsonObject deploy = deploy(entity.submission);
        Function<Executor, String> authenticatorO = sc.getAuthenticator();
        deploy.addProperty(ContextProperties.SSL_VERIFY, verify);
        JsonObject service;
        if (authenticatorO instanceof ICP4DAuthenticator) {
            ICP4DAuthenticator authenticator = (ICP4DAuthenticator) authenticatorO;
            service = authenticator.config(verify);
        } else if (authenticatorO instanceof StandaloneAuthenticator) {
            StandaloneAuthenticator authenticator = (StandaloneAuthenticator) authenticatorO;
            service = authenticator.config(verify);
            String buildServiceUrl = getConfigBuildServiceUrl(entity);
            if (buildServiceUrl == null) {
                buildServiceUrl = System.getenv(Util.STREAMS_BUILD_URL);
            }
            if (buildServiceUrl != null) {
                // Copy so we don't affect instance. Version of gson we
                // use lacks deepCopy() so we serialize / parse to copy.
                String json = service.toString();
                service = new JsonParser().parse(json).getAsJsonObject();
                JsonObject connInfo = service.getAsJsonObject(CONNECTION_INFO);
                if (connInfo.has(SERVICE_BUILD_ENDPOINT)) {
                    connInfo.remove(SERVICE_BUILD_ENDPOINT);
                }
                connInfo.addProperty(SERVICE_BUILD_ENDPOINT, buildServiceUrl);
            }
        } else {
            throw new IllegalStateException("Invalid Instance for Streams V5: " + cfgInstance);
        }
        deploy.add(StreamsKeys.SERVICE_DEFINITION, service);
    }
}
Also used : ICP4DAuthenticator(com.ibm.streamsx.rest.internal.ICP4DAuthenticator) Executor(org.apache.http.client.fluent.Executor) Instance(com.ibm.streamsx.rest.Instance) JsonObject(com.google.gson.JsonObject) StreamsConnection(com.ibm.streamsx.rest.StreamsConnection) StandaloneAuthenticator(com.ibm.streamsx.rest.internal.StandaloneAuthenticator) JsonParser(com.google.gson.JsonParser)

Example 7 with Instance

use of com.ibm.streamsx.rest.Instance in project streamsx.topology by IBMStreams.

the class RemoteEdgeContext method setSubmissionInstance.

static void setSubmissionInstance(AppEntity entity) throws IOException {
    Instance cfgInstance = getConfigInstance(entity);
    if (cfgInstance != null) {
        StreamsConnection sc = cfgInstance.getStreamsConnection();
        boolean verify = cfgInstance.getStreamsConnection().isVerify();
        JsonObject deploy = deploy(entity.submission);
        Function<Executor, String> authenticatorO = sc.getAuthenticator();
        deploy.addProperty(ContextProperties.SSL_VERIFY, verify);
        JsonObject service;
        if (authenticatorO instanceof ICP4DAuthenticator) {
            ICP4DAuthenticator authenticator = (ICP4DAuthenticator) authenticatorO;
            service = authenticator.config(verify);
        } else if (authenticatorO instanceof StandaloneAuthenticator) {
            StandaloneAuthenticator authenticator = (StandaloneAuthenticator) authenticatorO;
            service = authenticator.config(verify);
            String buildServiceUrl = getConfigBuildServiceUrl(entity);
            if (buildServiceUrl == null) {
                buildServiceUrl = System.getenv(Util.STREAMS_BUILD_URL);
            }
            if (buildServiceUrl != null) {
                // Copy so we don't affect instance. Version of gson we
                // use lacks deepCopy() so we serialize / parse to copy.
                String json = service.toString();
                service = new JsonParser().parse(json).getAsJsonObject();
                JsonObject connInfo = service.getAsJsonObject(CONNECTION_INFO);
                if (connInfo.has(SERVICE_BUILD_ENDPOINT)) {
                    connInfo.remove(SERVICE_BUILD_ENDPOINT);
                }
                connInfo.addProperty(SERVICE_BUILD_ENDPOINT, buildServiceUrl);
            }
        } else {
            throw new IllegalStateException("Invalid Instance for Streams V5: " + cfgInstance);
        }
        deploy.add(StreamsKeys.SERVICE_DEFINITION, service);
    }
}
Also used : ICP4DAuthenticator(com.ibm.streamsx.rest.internal.ICP4DAuthenticator) Executor(org.apache.http.client.fluent.Executor) Instance(com.ibm.streamsx.rest.Instance) JsonObject(com.google.gson.JsonObject) StreamsConnection(com.ibm.streamsx.rest.StreamsConnection) StandaloneAuthenticator(com.ibm.streamsx.rest.internal.StandaloneAuthenticator) JsonParser(com.google.gson.JsonParser)

Example 8 with Instance

use of com.ibm.streamsx.rest.Instance in project streamsx.topology by IBMStreams.

the class AnalyticsServiceStreamsContext method getSasServiceBase.

/**
 * Get the SAS OS version base.
 */
private static int getSasServiceBase(AppEntity entity) {
    // Need to interrogate the service to figure out
    // the os version of the service.
    StreamingAnalyticsService sas;
    try {
        sas = sas(entity);
        Instance instance = sas.getInstance();
        ActiveVersion ver = instance.getActiveVersion();
        // service force remote build.
        return Integer.valueOf(ver.getMinimumOSBaseVersion());
    } catch (IOException e) {
        ;
    }
    return -1;
}
Also used : StreamingAnalyticsService(com.ibm.streamsx.rest.StreamingAnalyticsService) Instance(com.ibm.streamsx.rest.Instance) ActiveVersion(com.ibm.streamsx.rest.ActiveVersion) IOException(java.io.IOException)

Example 9 with Instance

use of com.ibm.streamsx.rest.Instance in project streamsx.topology by IBMStreams.

the class InstanceTest method testOfEndpoint_configured.

@Test
public void testOfEndpoint_configured() throws IOException {
    assumeNotNull(System.getenv("CP4D_URL"));
    assumeNotNull(System.getenv("STREAMS_INSTANCE_ID"));
    Instance instance = Instance.ofEndpoint(null, null, null, null, sslVerify());
    check(instance);
}
Also used : Instance(com.ibm.streamsx.rest.Instance) Test(org.junit.Test)

Example 10 with Instance

use of com.ibm.streamsx.rest.Instance in project streamsx.topology by IBMStreams.

the class StreamingAnalyticsConnectionTest method getTestService.

static StreamingAnalyticsService getTestService() throws IOException {
    String serviceName = System.getenv("STREAMING_ANALYTICS_SERVICE_NAME");
    String vcapServices = System.getenv("VCAP_SERVICES");
    // if we don't have serviceName or vcapServices, skip the test
    assumeNotNull(serviceName, vcapServices);
    StreamingAnalyticsService service = StreamingAnalyticsService.of(null, null);
    Instance instance = service.getInstance();
    // bail if streaming analytics instance isn't up & running
    assumeTrue(instance.getStatus().equals("running"));
    return service;
}
Also used : StreamingAnalyticsService(com.ibm.streamsx.rest.StreamingAnalyticsService) Instance(com.ibm.streamsx.rest.Instance)

Aggregations

Instance (com.ibm.streamsx.rest.Instance)16 Test (org.junit.Test)6 StreamsConnection (com.ibm.streamsx.rest.StreamsConnection)5 JsonObject (com.google.gson.JsonObject)4 Job (com.ibm.streamsx.rest.Job)4 StreamingAnalyticsService (com.ibm.streamsx.rest.StreamingAnalyticsService)4 Metric (com.ibm.streamsx.rest.Metric)3 ProcessingElement (com.ibm.streamsx.rest.ProcessingElement)3 JobConfig (com.ibm.streamsx.topology.jobconfig.JobConfig)3 JsonParser (com.google.gson.JsonParser)2 InputPort (com.ibm.streamsx.rest.InputPort)2 Operator (com.ibm.streamsx.rest.Operator)2 OutputPort (com.ibm.streamsx.rest.OutputPort)2 RESTException (com.ibm.streamsx.rest.RESTException)2 ICP4DAuthenticator (com.ibm.streamsx.rest.internal.ICP4DAuthenticator)2 StandaloneAuthenticator (com.ibm.streamsx.rest.internal.StandaloneAuthenticator)2 IOException (java.io.IOException)2 Executor (org.apache.http.client.fluent.Executor)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1