Search in sources :

Example 1 with MatchingEngine

use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.

the class ComputerVisionRestUnitTest method registerAndFindCloudlet.

/*
     * Return url of MobiledgeXSDK Demo backend
     */
private String registerAndFindCloudlet(Context ctx) {
    MatchingEngine me = new MatchingEngine(ctx);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    try {
        AppClient.RegisterClientRequest registerRequest = me.createDefaultRegisterClientRequest(ctx, orgName).setAppName(appName).setAppVers(appVers).build();
        AppClient.RegisterClientReply registerReply = me.registerClient(registerRequest, GRPC_TIMEOUT_MS);
        Thread.sleep(4000);
        if (registerReply == null) {
            Log.e(TAG, "Register Client reply is null");
            return null;
        }
        if (registerReply.getStatus() != AppClient.ReplyStatus.RS_SUCCESS) {
            Log.e(TAG, "Register Client reply status is " + registerReply.getStatus());
            return null;
        }
        Location location = new Location("MobiledgeX_Loc_Sim");
        location.setLatitude(latitude);
        location.setLongitude(longitude);
        AppClient.FindCloudletRequest findCloudletRequest = me.createDefaultFindCloudletRequest(ctx, location).build();
        AppClient.FindCloudletReply findCloudletReply = me.findCloudlet(findCloudletRequest, GRPC_TIMEOUT_MS);
        if (findCloudletReply == null) {
            Log.e(TAG, "Find Cloudlet reply is null");
            return null;
        }
        if (findCloudletReply.getStatus() != AppClient.FindCloudletReply.FindStatus.FIND_FOUND) {
            Log.e(TAG, "Find Cloudlet find status is " + findCloudletReply.getStatus());
            return null;
        }
        String fqdn = findCloudletReply.getFqdn();
        Appcommon.AppPort appPort = findCloudletReply.getPorts(0);
        int publicPort = appPort.getPublicPort();
        String fqdnPrefix = appPort.getFqdnPrefix();
        return "http://" + fqdnPrefix + fqdn + ":" + publicPort;
    } catch (DmeDnsException dde) {
        Log.e(TAG, "ExecutionException registering client. " + dde.getMessage());
        return null;
    } catch (ExecutionException ee) {
        Log.e(TAG, "ExecutionException registering client. " + ee.getMessage());
        return null;
    } catch (InterruptedException ie) {
        Log.e(TAG, "InterruptedException registering client. " + ie.getMessage());
        return null;
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.e(TAG, "InterruptedException registering client. " + nnfe.getMessage());
        return null;
    }
}
Also used : MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) Appcommon(distributed_match_engine.Appcommon) PackageManager(android.content.pm.PackageManager) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) Location(android.location.Location) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException)

Example 2 with MatchingEngine

use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.

the class MainActivity method onResume.

@Override
public void onResume() {
    super.onResume();
    if (mRpUtil.getNeededPermissions(this).size() > 0) {
        // Opens a UI. When it returns, onResume() is called again.
        mRpUtil.requestMultiplePermissions(this);
        return;
    }
    if (me == null) {
        // ! [matchingengine_constructor]
        // Permissions must be available. Check permissions upon OnResume(). Create a MobiledgeX MatchingEngine instance.
        me = new MatchingEngine(this);
        // ! [matchingengine_constructor]
        // ! [enable_edgeevents]
        // Register the class subscribing to EdgeEvents to the EdgeEventsBus (Guava EventBus interface).
        // default is true.
        me.setEnableEdgeEvents(true);
        // ! [enable_edgeevents]
        // ! [edgeevents_subsscriber_setup_example]
        mEdgeEventsSubscriber = new EdgeEventsSubscriber();
        me.getEdgeEventsBus().register(mEdgeEventsSubscriber);
        // set a default config.
        // There is also a parameterized version to further customize.
        EdgeEventsConfig backgroundEdgeEventsConfig = me.createDefaultEdgeEventsConfig();
        backgroundEdgeEventsConfig.latencyTestType = NetTest.TestType.CONNECT;
        // This is the internal port, that has not been remapped to a public port for a particular appInst.
        // 0 will favor the first TCP port if found for connect test.
        backgroundEdgeEventsConfig.latencyInternalPort = 3765;
        // Latency config. There is also a very similar location update config.
        // Default is 0, which means test forever.
        backgroundEdgeEventsConfig.latencyUpdateConfig.maxNumberOfUpdates = 0;
        // The default is 30.
        backgroundEdgeEventsConfig.latencyUpdateConfig.updateIntervalSeconds = 7;
        backgroundEdgeEventsConfig.latencyThresholdTrigger = 186;
        // ! [edgeevents_subsscriber_setup_example]
        // backgroundEdgeEventsConfig.latencyUpdateConfig = null;
        // backgroundEdgeEventsConfig.locationUpdateConfig = null; // app driven.
        // ! [startedgeevents_example]
        me.startEdgeEvents(backgroundEdgeEventsConfig);
    // ! [startedgeevents_example]
    }
    if (mDoLocationUpdates) {
        startLocationUpdates();
    }
}
Also used : EdgeEventsConfig(com.mobiledgex.matchingengine.edgeeventsconfig.EdgeEventsConfig) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine)

Example 3 with MatchingEngine

use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.

the class MatchingEngineUnitTest method testRegisterClient.

@Test
public void testRegisterClient() {
    Context ctx = getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(ctx);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    registerClient(me, ctx);
}
Also used : Context(android.content.Context) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) Test(org.junit.Test)

Example 4 with MatchingEngine

use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.

the class MatchingEngineUnitTest method testFindCloudletPerformance.

@Test
public void testFindCloudletPerformance() {
    Context ctx = getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(ctx);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    registerClient(me, ctx);
    Location location = new Location("MobiledgeX_Loc_Sim");
    location.setLatitude(latitude);
    location.setLongitude(longitude);
    try {
        AppClient.FindCloudletRequest request = me.createDefaultFindCloudletRequest(ctx, location).build();
        AppClient.FindCloudletReply reply = me.findCloudlet(request, GRPC_TIMEOUT_MS, MatchingEngine.FindCloudletMode.PERFORMANCE);
        assertTrue("Unable to get FindCloudletReply", reply != null);
        assertEquals("FindCloudlet status is " + reply.getStatus(), AppClient.FindCloudletReply.FindStatus.FIND_FOUND, reply.getStatus());
        assertTrue("Fqdn in FindCloudletReply is " + reply.getFqdn(), reply.getFqdn() != null && reply.getFqdn() != "");
        Log.i(TAG, "cloudlet location=" + reply.getCloudletLocation().getLatitude() + "," + reply.getCloudletLocation().getLongitude());
        assertNotEquals("Latitude should not be 0.0, but it is", 0.0, reply.getCloudletLocation().getLatitude());
        assertNotEquals("Longitude should not be 0.0, but it is", 0.0, reply.getCloudletLocation().getLongitude());
    } catch (DmeDnsException dde) {
        assertTrue("ExecutionException finding cloudlet. " + dde.getMessage(), false);
    } catch (ExecutionException ee) {
        assertTrue("ExecutionException finding cloudlet. " + ee.getMessage(), false);
    } catch (InterruptedException ie) {
        assertTrue("InterruptedException finding cloudlet. " + ie.getMessage(), false);
    }
}
Also used : Context(android.content.Context) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) Location(android.location.Location) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Example 5 with MatchingEngine

use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.

the class MatchingEngineUnitTest method testGetAppInstList.

@Test
public void testGetAppInstList() {
    Context ctx = getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(ctx);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    registerClient(me, ctx);
    Location location = new Location("MobiledgeX_Loc_Sim");
    location.setLatitude(latitude);
    location.setLongitude(longitude);
    try {
        AppClient.AppInstListRequest request = me.createDefaultAppInstListRequest(ctx, location).build();
        AppClient.AppInstListReply reply = me.getAppInstList(request, GRPC_TIMEOUT_MS);
        assertTrue("Unable to get AppInstListReply", reply != null);
        assertEquals("AppInstListReply status is " + reply.getStatus(), AppClient.AppInstListReply.AIStatus.AI_SUCCESS, reply.getStatus());
    } catch (DmeDnsException dde) {
        assertTrue("ExecutionException getting app inst list. " + dde.getMessage(), false);
    } catch (ExecutionException ee) {
        assertTrue("ExecutionException getting app inst list. " + ee.getMessage(), false);
    } catch (InterruptedException ie) {
        assertTrue("InterruptedException getting app inst list. " + ie.getMessage(), false);
    }
}
Also used : Context(android.content.Context) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) Location(android.location.Location) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Aggregations

MatchingEngine (com.mobiledgex.matchingengine.MatchingEngine)34 AppClient (distributed_match_engine.AppClient)30 Context (android.content.Context)29 DmeDnsException (com.mobiledgex.matchingengine.DmeDnsException)29 ExecutionException (java.util.concurrent.ExecutionException)29 Test (org.junit.Test)29 Location (android.location.Location)26 StatusRuntimeException (io.grpc.StatusRuntimeException)19 PackageManager (android.content.pm.PackageManager)16 IOException (java.io.IOException)8 AppConnectionManager (com.mobiledgex.matchingengine.AppConnectionManager)5 AppPort (distributed_match_engine.Appcommon.AppPort)4 OkHttpClient (com.squareup.okhttp.OkHttpClient)3 Request (com.squareup.okhttp.Request)3 Response (com.squareup.okhttp.Response)3 Appcommon (distributed_match_engine.Appcommon)3 Socket (java.net.Socket)3 DecodeException (com.auth0.android.jwt.DecodeException)2 MediaType (com.squareup.okhttp.MediaType)2 RequestBody (com.squareup.okhttp.RequestBody)2