mesosphere.marathon.client.Marathon Java Examples
The following examples show how to use
mesosphere.marathon.client.Marathon.
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: MarathonBuilderImpl.java From marathon-plugin with Apache License 2.0 | 6 votes |
/** * Get a Marathon client with Authorization headers using the token within provided credentials. If the content of * credentials is JSON, this will use the "jenkins_token" field; if the content is just a string, that will be * used as the token value. * * @param credentials String credentials * @return Marathon client with token in auth header */ private Marathon getMarathonClient(StringCredentials credentials) { String token; try { final JSONObject json = JSONObject.fromObject(credentials.getSecret().getPlainText()); if (json.has("jenkins_token")) { token = json.getString("jenkins_token"); } else { token = ""; } } catch (JSONException jse) { token = credentials.getSecret().getPlainText(); } if (StringUtils.isNotEmpty(token)) { return MarathonClient .getInstanceWithTokenAuth(getURL(), token); } return getMarathonClient(); }
Example #2
Source File: MarathonBuilderImpl.java From marathon-plugin with Apache License 2.0 | 6 votes |
/** * Construct a Marathon client based on the provided credentialsId and execute an update for the configuration's * Marathon application. * * @param credentialsId A string ID for a credential within Jenkin's Credential store * @throws MarathonException thrown if the Marathon service has an error */ private void doUpdate(final String credentialsId) throws MarathonException { final Credentials credentials = MarathonBuilderUtils.getJenkinsCredentials(credentialsId, Credentials.class); Marathon client; if (credentials instanceof UsernamePasswordCredentials) { client = getMarathonClient((UsernamePasswordCredentials) credentials); } else if (credentials instanceof StringCredentials) { client = getMarathonClient((StringCredentials) credentials); } else { client = getMarathonClient(); } if (client != null) { client.updateApp(getApp().getId(), getApp(), config.getForceUpdate()); } }
Example #3
Source File: MarathonAutoConfiguration.java From spring-cloud-marathon with MIT License | 5 votes |
@Bean @ConditionalOnMissingBean public Marathon marathonClient(MarathonProperties properties) { return new RibbonMarathonClient.Builder(properties.getEndpoint()) .withListOfServers(properties.getListOfServers()) .withToken(properties.getToken()) .withUsername(properties.getUsername()) .withPassword(properties.getPassword()) .build(); }
Example #4
Source File: AuthEnabledMarathonClient.java From pravega with Apache License 2.0 | 5 votes |
private static Marathon getInstance(String endpoint, RequestInterceptor... interceptors) { Feign.Builder b = Feign.builder().client(LoginClient.getClientHostVerificationDisabled()) .logger(new Logger.ErrorLogger()) .logLevel(Logger.Level.BASIC) .encoder(new GsonEncoder(ModelUtils.GSON)) .decoder(new GsonDecoder(ModelUtils.GSON)) .errorDecoder(new MarathonErrorDecoder()) //max wait period = 5 seconds ; max attempts = 5 .retryer(new Retryer.Default(SECONDS.toMillis(1), SECONDS.toMillis(5), 5)); if (interceptors != null) { b.requestInterceptors(asList(interceptors)); } b.requestInterceptor(new MarathonHeadersInterceptor()); return b.target(Marathon.class, endpoint); }
Example #5
Source File: MarathonTestSupport.java From spring-cloud-deployer-mesos with Apache License 2.0 | 5 votes |
@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 #6
Source File: MesosAutoConfiguration.java From spring-cloud-deployer-mesos with Apache License 2.0 | 5 votes |
@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 #7
Source File: MarathonEndpointTests.java From spring-cloud-marathon with MIT License | 5 votes |
@Bean public Marathon marathonClient(MarathonProperties properties) throws MarathonException { Marathon client = mock(Marathon.class); when(client.getServerInfo()).thenReturn(new GetServerInfoResponse()); GetAppsResponse appsResponse = new GetAppsResponse(); VersionedApp app = new VersionedApp(); app.setId("test-app"); appsResponse.setApps(Collections.singletonList(app)); when(client.getApps()).thenReturn(appsResponse); return client; }
Example #8
Source File: MarathonRibbonClientConfiguration.java From spring-cloud-marathon with MIT License | 5 votes |
@Autowired public MarathonRibbonClientConfiguration(Marathon client, IClientConfig clientConfig, MarathonDiscoveryProperties properties) { this.client = client; this.clientConfig = clientConfig; this.properties = properties; }
Example #9
Source File: MarathonServerList.java From spring-cloud-marathon with MIT License | 5 votes |
public MarathonServerList(Marathon client, MarathonDiscoveryProperties properties) { this.client = client; this.properties = properties; this.queryMap = new HashMap<>(); this.ignoreServiceId = false; metaDataFilter = new HashMap<>(); }
Example #10
Source File: MarathonEndpoint.java From spring-cloud-marathon with MIT License | 4 votes |
@Autowired public MarathonEndpoint(Marathon marathon) { this.marathon = marathon; }
Example #11
Source File: ExternalVolumeTest.java From marathon-client with Apache License 2.0 | 4 votes |
@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 #12
Source File: AuthEnabledMarathonClient.java From pravega with Apache License 2.0 | 4 votes |
private static Marathon createMarathonClient() { String token = LoginClient.getAuthToken(LOGIN_URL); return getInstance(ENDPOINT, new TokenAuthRequestInterceptor(token)); }
Example #13
Source File: AuthEnabledMarathonClient.java From pravega with Apache License 2.0 | 4 votes |
public static Marathon getClient() { return createMarathonClient(); }
Example #14
Source File: MarathonAutoConfiguration.java From spring-cloud-marathon with MIT License | 4 votes |
@Bean @ConditionalOnMissingBean @ConditionalOnProperty(value = "spring.cloud.discovery.client.marathon.health-indicator.enabled", matchIfMissing = true ) public MarathonHealthIndicator healthIndicator(Marathon client) { return new MarathonHealthIndicator(client); }
Example #15
Source File: MarathonTestSupport.java From spring-cloud-deployer-mesos with Apache License 2.0 | 4 votes |
@Override protected void obtainResource() throws Exception { context = new SpringApplicationBuilder(Config.class).web(false).run(); resource = context.getBean(Marathon.class); resource.getServerInfo(); }
Example #16
Source File: MesosAutoConfiguration.java From spring-cloud-deployer-mesos with Apache License 2.0 | 4 votes |
@Bean @RefreshScope public AppDeployer appDeployer(MarathonAppDeployerProperties marathonProperties, Marathon marathon) { return new MarathonAppDeployer(marathonProperties, marathon); }
Example #17
Source File: MarathonAutoConfiguration.java From spring-cloud-marathon with MIT License | 4 votes |
@Bean @ConditionalOnMissingBean public MarathonEndpoint marathonEndpoint(Marathon client) { return new MarathonEndpoint(client); }
Example #18
Source File: MarathonAppDeployer.java From spring-cloud-deployer-mesos with Apache License 2.0 | 4 votes |
@Autowired public MarathonAppDeployer(MarathonAppDeployerProperties properties, Marathon marathon) { this.properties = properties; this.marathon = marathon; }
Example #19
Source File: MarathonHealthConfigErrorTests.java From spring-cloud-marathon with MIT License | 4 votes |
@Bean public Marathon marathonClient(MarathonProperties properties) { return mock(Marathon.class); }
Example #20
Source File: MarathonEndpointErrorTests.java From spring-cloud-marathon with MIT License | 4 votes |
@Bean public Marathon marathonClient(MarathonProperties properties) { return mock(Marathon.class); }
Example #21
Source File: MarathonDiscoveryClient.java From spring-cloud-marathon with MIT License | 4 votes |
public MarathonDiscoveryClient(Marathon client) { this.client = client; }
Example #22
Source File: MarathonHealthConfigTests.java From spring-cloud-marathon with MIT License | 4 votes |
@Bean public Marathon marathonClient(MarathonProperties properties) { return mock(Marathon.class, withSettings().defaultAnswer(Answers.RETURNS_MOCKS.get())); }
Example #23
Source File: MarathonHealthIndicator.java From spring-cloud-marathon with MIT License | 4 votes |
public MarathonHealthIndicator(Marathon client) { this.client = client; }
Example #24
Source File: MarathonBuilderImpl.java From marathon-plugin with Apache License 2.0 | 2 votes |
/** * 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()); }
Example #25
Source File: MarathonBuilderImpl.java From marathon-plugin with Apache License 2.0 | 2 votes |
/** * Get a Marathon client with basic auth using the username and password within the provided credentials. * * @param credentials Username and password credentials * @return Marathon client with basic authentication filled in */ private Marathon getMarathonClient(UsernamePasswordCredentials credentials) { return MarathonClient .getInstanceWithBasicAuth(getURL(), credentials.getUsername(), credentials.getPassword().getPlainText()); }