Java Code Examples for mesosphere.marathon.client.MarathonClient#getInstance()

The following examples show how to use mesosphere.marathon.client.MarathonClient#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MesosAutoConfiguration.java    From spring-cloud-deployer-mesos with Apache License 2.0 5 votes vote down vote up
@Bean
@RefreshScope
public Marathon marathon(MarathonAppDeployerProperties marathonProperties, DcosClusterProperties dcosClusterProperties) {
	if (StringUtils.hasText(dcosClusterProperties.getAuthorizationToken())) {
		return MarathonClient.getInstance(marathonProperties.getApiEndpoint(),
				new DcosHeadersInterceptor(dcosClusterProperties.getAuthorizationToken()));
	}
	else {
		return MarathonClient.getInstance(marathonProperties.getApiEndpoint());
	}
}
 
Example 2
Source File: MarathonTestSupport.java    From spring-cloud-deployer-mesos with Apache License 2.0 5 votes vote down vote up
@Bean
public Marathon marathon(MarathonAppDeployerProperties marathonProperties,
                         DcosClusterProperties dcosClusterProperties) {
	if (StringUtils.hasText(dcosClusterProperties.getAuthorizationToken())) {
		return MarathonClient.getInstance(marathonProperties.getApiEndpoint(),
				new DcosHeadersInterceptor(dcosClusterProperties.getAuthorizationToken()));
	}
	else {
		return MarathonClient.getInstance(marathonProperties.getApiEndpoint());
	}
}
 
Example 3
Source File: MarathonContainer.java    From minimesos with Apache License 2.0 5 votes vote down vote up
/**
 * Deploys a Marathon app by JSON string
 *
 * @param marathonJson JSON string
 */
@Override
public void deployApp(String marathonJson) {
    mesosphere.marathon.client.Marathon marathon = MarathonClient.getInstance(getMarathonEndpoint());
    try {
        marathon.createApp(constructApp(marathonJson));
    } catch (MarathonException e) {
        throw new MinimesosException("Marathon did not accept the app, error: " + e.toString());
    }
    LOGGER.debug(format("Installed app at '%s'", getMarathonEndpoint()));
}
 
Example 4
Source File: MarathonContainer.java    From minimesos with Apache License 2.0 5 votes vote down vote up
@Override
public Result deleteApp(String appId) {
    mesosphere.marathon.client.Marathon marathon = MarathonClient.getInstance(getMarathonEndpoint());
    try {
        Result result = marathon.deleteApp(appId);
        LOGGER.debug(format("Deleted app '%s' at '%s'", appId, getMarathonEndpoint()));
        return result;
    } catch (MarathonException e) {
        throw new MinimesosException("Could not delete app '" + appId  + "'. " + e.getMessage());
    }
}
 
Example 5
Source File: MarathonContainer.java    From minimesos with Apache License 2.0 5 votes vote down vote up
@Override
public void deployGroup(String groupJson) {
    mesosphere.marathon.client.Marathon marathon = MarathonClient.getInstance(getMarathonEndpoint());
    try {
        Group group = constructGroup(groupJson);
        marathon.createGroup(group);
    } catch (Exception e) {
        throw new MinimesosException("Marathon did not accept the app, error: " + e.toString(), e);
    }
    LOGGER.debug(format("Installing group at %s", getMarathonEndpoint()));
}
 
Example 6
Source File: MarathonContainer.java    From minimesos with Apache License 2.0 5 votes vote down vote up
@Override
public Result deleteGroup(String groupId) {
    mesosphere.marathon.client.Marathon marathon = MarathonClient.getInstance(getMarathonEndpoint());
    try {
        Result result = marathon.deleteGroup(groupId);
        LOGGER.debug(format("Deleted app '%s' at '%s'", groupId, getMarathonEndpoint()));
        return result;
    } catch (MarathonException e) {
        throw new MinimesosException("Could not delete group '" + groupId  + "'. " + e.getMessage());
    }
}
 
Example 7
Source File: MarathonContainer.java    From minimesos with Apache License 2.0 5 votes vote down vote up
/**
 * Updates a Marathon app by JSON string
 *
 * @param marathonJson JSON string
 */
@Override
public void updateApp(String marathonJson) {
    mesosphere.marathon.client.Marathon marathon = MarathonClient.getInstance(getMarathonEndpoint());
    try {
        App app = constructApp(marathonJson);
        marathon.updateApp(app.getId(), app, true);
    } catch (MarathonException e) {
        throw new MinimesosException("Marathon could not update the app, error: " + e.toString());
    }
    LOGGER.debug(format("Installing an app on marathon %s", getMarathonEndpoint()));
}
 
Example 8
Source File: ExternalVolumeTest.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testExternalVolumes() throws Exception {
    final MockWebServer server = new MockWebServer();
    final String mockResponse = "{\"container\": {\"volumes\": [" +
            "{\"containerPath\":\"/data/db\",\"mode\":\"RW\",\"external\":" +
            "{\"name\":\"mongodb-testvol\",\"provider\":\"dvdi\",\"options\":" +
            "{\"dvdi/driver\":\"rexray\"}}}]}}";

    try {
        server.enqueue(new MockResponse().setBody(mockResponse));
        server.start();
        Marathon client = MarathonClient.getInstance(server.url("/").toString());

        App app = new App();
        app.setId("mongo");
        app.setCpus(1.0);
        app.setMem(256.0);
        app.setContainer(new Container());
        app.getContainer().setDocker(new Docker());
        app.getContainer().getDocker().setImage("mongo");
        app.getContainer().setVolumes(new ArrayList<Volume>());

        ExternalVolume externalVolume = new ExternalVolume();
        externalVolume.setName("mongodb-testvol");
        externalVolume.setMode("RW");
        externalVolume.setContainerPath("/data/db");
        externalVolume.setProvider("dvdi");
        externalVolume.setDriver("rexray");

        app.getContainer().getVolumes().add(externalVolume);

        final App appRes = client.createApp(app);
        assertFalse(appRes.getContainer().getVolumes().isEmpty());

        ExternalVolume responseVolume = (ExternalVolume) appRes.getContainer().getVolumes().iterator().next();
        assertEquals("mongodb-testvol", responseVolume.getExternalVolumeInfo().getName());

        RecordedRequest request = server.takeRequest();
        assertNotNull(request);

        final String requestBody = request.getBody().readUtf8();
        assertNotNull(requestBody);

        // request to JSON
        JsonObject requestPayload = new Gson().fromJson(requestBody, JsonObject.class);
        assertNotNull(requestPayload);
        JsonObject requestVolume = requestPayload.getAsJsonObject("container").getAsJsonArray("volumes").get(0).getAsJsonObject();
        assertNotNull(requestVolume);
        assertEquals("RW", requestVolume.get("mode").getAsString());
        assertEquals("/data/db", requestVolume.get("containerPath").getAsString());
    } finally {
        server.shutdown();
    }
}
 
Example 9
Source File: MarathonBuilderImpl.java    From marathon-plugin with Apache License 2.0 2 votes vote down vote up
/**
 * Get a default Marathon client. This does not include any authentication headers.
 *
 * @return Marathon client without authentication mechanisms
 */
private Marathon getMarathonClient() {
    return MarathonClient.getInstance(getURL());
}