mesosphere.marathon.client.model.v2.GetAppResponse Java Examples

The following examples show how to use mesosphere.marathon.client.model.v2.GetAppResponse. 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: MarathonDiscoveryClient.java    From spring-cloud-marathon with MIT License 6 votes vote down vote up
private List<ServiceInstance> getInstances(Map<String, String> queryMap) throws MarathonException {
    List<ServiceInstance> instances = new ArrayList<>();

    GetAppsResponse appsResponse = queryMap == null ? client.getApps() : client.getApps(queryMap);

    if (appsResponse != null && appsResponse.getApps() != null) {
        List<VersionedApp> apps = appsResponse.getApps();

        log.debug("Discovered {} service{}{}", apps.size(), apps.size() == 1 ? "" : "s", queryMap == null ? "" : String.format(" with ids that contain [%s]", queryMap.get("id")));

        for (App app : apps) {
            // Fetch data for this specific service id, to collect task information
            GetAppResponse response = client.getApp(app.getId());

            if (response != null && response.getApp() != null) {
                instances.addAll(extractServiceInstances(response.getApp()));
            }
        }
    }

    return instances;
}
 
Example #2
Source File: MarathonBasedService.java    From pravega with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRunning() {
    try {
        GetAppResponse app = marathonClient.getApp(this.id);
        log.debug("App Details: {}", app);
        //app is not running until the desired instance count is equal to the number of task/docker containers
        // and the state of application is healthy.
        if ((app.getApp().getTasksRunning().intValue() == app.getApp().getInstances().intValue())
                && app.getApp().getTasksRunning().intValue() == app.getApp().getTasksHealthy().intValue()) {
            log.info("App {} is running", this.id);
            return true;
        } else {
            log.info("App {} is not running", this.id);
            return false;
        }
    } catch (MarathonException ex) {
        if (ex.getStatus() == NOT_FOUND.code()) {
            log.info("App is not running : {}", this.id);
            return false;
        }
        throw new TestFrameworkException(RequestFailed, "Marathon Exception while fetching service details", ex);
    }
}
 
Example #3
Source File: MarathonDiscoveryClient.java    From spring-cloud-marathon with MIT License 5 votes vote down vote up
private List<ServiceInstance> getInstance(String serviceId) throws MarathonException {
    List<ServiceInstance> instances = new ArrayList<>();

    GetAppResponse response = client.getApp(ServiceIdConverter.convertToMarathonId(serviceId));

    if (response != null && response.getApp() != null) {
        instances.addAll(extractServiceInstances(response.getApp()));
    }

    return instances;
}
 
Example #4
Source File: Marathon.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@RequestLine("GET /v2/apps/{id}")
@Headers(HeaderUtils.MARATHON_API_SOURCE_HEADER)
GetAppResponse getApp(@Param("id") String id) throws MarathonException;
 
Example #5
Source File: MarathonServerListTests.java    From spring-cloud-marathon with MIT License 4 votes vote down vote up
@Before
public void setup() throws MarathonException {
    serverList = new MarathonServerList(
            marathonClient,
            new MarathonDiscoveryProperties()
    );

    IClientConfig config = mock(IClientConfig.class);
    when(config.getClientName()).thenReturn("service1");

    Map<String, Object> properties = new HashMap<>();
    properties.put("IgnoreServiceId",false);
    when(config.getProperties()).thenReturn(properties);

    serverList.initWithNiwsConfig(config);

    GetAppResponse appResponse = new GetAppResponse();

    when(marathonClient.getApp("/service1"))
            .thenReturn(appResponse);

    VersionedApp app = new VersionedApp();
    appResponse.setApp(app);

    app.setTasks(IntStream.of(1,2)
                    .mapToObj(index -> {
                        Task task = new Task();
                        task.setHost("host" + index);
                        task.setPorts(IntStream.of(9090, 9091)
                                .boxed()
                                .collect(Collectors.toList()));
                        task.setHealthCheckResults(Collections.emptyList());
                        return task;
                    }).collect(Collectors.toList())
    );

    Task withNullHealthChecks = new Task();
    withNullHealthChecks.setHost("host3");
    withNullHealthChecks.setPorts(IntStream.of(9090, 9091)
            .boxed()
            .collect(Collectors.toList()));
    app.getTasks().add(withNullHealthChecks);
}
 
Example #6
Source File: MarathonServerListByLabelTests.java    From spring-cloud-marathon with MIT License 4 votes vote down vote up
@Before
public void setup() throws MarathonException {
    serverList = new MarathonServerList(
            marathonClient,
            new MarathonDiscoveryProperties()
    );

    IClientConfig config = mock(IClientConfig.class);
    when(config.getClientName()).thenReturn("service1");

    LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
    properties.put("IgnoreServiceId",true);
    properties.put("MetaDataFilter.A","A");
    properties.put("MetaDataFilter.B","in(V1,V2,V3)");
    properties.put("MetaDataFilter.C","!=X");
    properties.put("MetaDataFilter.D","==Y");
    properties.put("MetaDataFilter.E","notin(1,2,3)");
    when(config.getProperties()).thenReturn(properties);

    serverList.initWithNiwsConfig(config);

    GetAppResponse appResponse = new GetAppResponse();

    when(marathonClient.getApp("/service1"))
            .thenReturn(appResponse);

    GetAppsResponse appsResponse = new GetAppsResponse();

    Map<String,String> queryMap = new HashMap<>();
    queryMap.put("label","A==A,B in(V1,V2,V3),C!=X,D==Y,E notin(1,2,3)");
    when(marathonClient.getApps(queryMap))
            .thenReturn(appsResponse);

    VersionedApp app = new VersionedApp();
    appResponse.setApp(app);

    app.setId("/service1");
    app.setTasks(IntStream.of(1,2)
            .mapToObj(index -> {
                Task task = new Task();
                task.setHost("host" + index);
                task.setPorts(IntStream.of(9090, 9091)
                        .boxed()
                        .collect(Collectors.toList()));
                task.setHealthCheckResults(Collections.emptyList());
                return task;
            }).collect(Collectors.toList())
    );

    Task withNullHealthChecks = new Task();
    withNullHealthChecks.setHost("host3");
    withNullHealthChecks.setPorts(IntStream.of(9090, 9091)
            .boxed()
            .collect(Collectors.toList()));
    app.getTasks().add(withNullHealthChecks);

    List<VersionedApp> apps = new ArrayList<>();
    apps.add(app);
    appsResponse.setApps(apps);

}
 
Example #7
Source File: MarathonServerListFetchZoneTests.java    From spring-cloud-marathon with MIT License 4 votes vote down vote up
@Before
public void setup() throws MarathonException {
    serverList = new MarathonServerList(
            marathonClient,
            new MarathonDiscoveryProperties()
    );

    IClientConfig config = mock(IClientConfig.class);
    when(config.getClientName()).thenReturn("service1");

    Map<String, Object> properties = new HashMap<>();
    properties.put("ZonePattern",".+\\.(.+)");
    when(config.getProperties()).thenReturn(properties);

    serverList.initWithNiwsConfig(config);

    GetAppResponse appResponse = new GetAppResponse();

    when(marathonClient.getApp("/service1"))
            .thenReturn(appResponse);

    GetAppsResponse appsResponse = new GetAppsResponse();

    when(marathonClient.getApps())
            .thenReturn(appsResponse);

    VersionedApp app = new VersionedApp();
    appResponse.setApp(app);

    app.setId("/service1");
    app.setTasks(IntStream.of(1,2)
            .mapToObj(index -> {
                Task task = new Task();
                task.setHost("host" + index + ".dc1");
                task.setPorts(IntStream.of(9090, 9091)
                        .boxed()
                        .collect(Collectors.toList()));
                task.setHealthCheckResults(Collections.emptyList());
                return task;
            }).collect(Collectors.toList())
    );

    Task withNullHealthChecks = new Task();
    withNullHealthChecks.setHost("host1.dc2");
    withNullHealthChecks.setPorts(IntStream.of(9090, 9091)
            .boxed()
            .collect(Collectors.toList()));
    app.getTasks().add(withNullHealthChecks);

    List<VersionedApp> apps = new ArrayList<>();
    apps.add(app);
    appsResponse.setApps(apps);

}
 
Example #8
Source File: MarathonServerListIgnoreServiceIdTests.java    From spring-cloud-marathon with MIT License 4 votes vote down vote up
@Before
public void setup() throws MarathonException {
    serverList = new MarathonServerList(
            marathonClient,
            new MarathonDiscoveryProperties()
    );

    IClientConfig config = mock(IClientConfig.class);
    when(config.getClientName()).thenReturn("service1");

    Map<String, Object> properties = new HashMap<>();
    properties.put("IgnoreServiceId",true);
    when(config.getProperties()).thenReturn(properties);

    serverList.initWithNiwsConfig(config);

    GetAppResponse appResponse = new GetAppResponse();

    when(marathonClient.getApp("/service1"))
            .thenReturn(appResponse);

    GetAppsResponse appsResponse = new GetAppsResponse();

    Map<String,String> queryMap = new HashMap<>();
    when(marathonClient.getApps(queryMap))
            .thenReturn(appsResponse);

    VersionedApp app = new VersionedApp();
    appResponse.setApp(app);

    app.setId("/service1");
    app.setTasks(IntStream.of(1,2)
            .mapToObj(index -> {
                Task task = new Task();
                task.setHost("host" + index);
                task.setPorts(IntStream.of(9090, 9091)
                        .boxed()
                        .collect(Collectors.toList()));
                task.setHealthCheckResults(Collections.emptyList());
                return task;
            }).collect(Collectors.toList())
    );

    Task withNullHealthChecks = new Task();
    withNullHealthChecks.setHost("host3");
    withNullHealthChecks.setPorts(IntStream.of(9090, 9091)
            .boxed()
            .collect(Collectors.toList()));
    app.getTasks().add(withNullHealthChecks);

    List<VersionedApp> apps = new ArrayList<>();
    apps.add(app);
    appsResponse.setApps(apps);

}
 
Example #9
Source File: MarathonDiscoveryClientTests.java    From spring-cloud-marathon with MIT License 4 votes vote down vote up
@Test
public void test_list_of_instances() throws MarathonException {
    GetAppResponse appResponse = new GetAppResponse();

    when(marathonClient.getApp("/app1"))
            .thenReturn(appResponse);

    appResponse.setApp(new VersionedApp());
    appResponse.getApp().setTasks(new ArrayList<>());

    Task taskWithNoHealthChecks = new Task();
    taskWithNoHealthChecks.setAppId("/app1");
    taskWithNoHealthChecks.setHost("host1");
    taskWithNoHealthChecks.setPorts(
            IntStream.of(9090)
            .boxed()
            .collect(Collectors.toList())
    );

    appResponse.getApp().getTasks().add(taskWithNoHealthChecks);

    Task taskWithAllGoodHealthChecks = new Task();
    taskWithAllGoodHealthChecks.setAppId("/app1");
    taskWithAllGoodHealthChecks.setHost("host2");
    taskWithAllGoodHealthChecks.setPorts(
            IntStream.of(9090, 9091)
                    .boxed()
                    .collect(Collectors.toList())
    );

    HealthCheckResults healthCheckResult = new HealthCheckResults();
    healthCheckResult.setAlive(true);

    HealthCheckResults badHealthCheckResult = new HealthCheckResults();
    badHealthCheckResult.setAlive(false);

    List<HealthCheckResults> healthCheckResults = new ArrayList<>();
    healthCheckResults.add(healthCheckResult);
    healthCheckResults.add(healthCheckResult);

    taskWithAllGoodHealthChecks.setHealthCheckResults(healthCheckResults);

    appResponse.getApp().getTasks().add(taskWithAllGoodHealthChecks);

    Task taskWithOneBadHealthCheck = new Task();
    taskWithOneBadHealthCheck.setAppId("/app1");
    taskWithOneBadHealthCheck.setHost("host3");
    taskWithOneBadHealthCheck.setPorts(
            IntStream.of(9090)
                    .boxed()
                    .collect(Collectors.toList())
    );

    List<HealthCheckResults> withBadHealthCheckResults = new ArrayList<>();
    withBadHealthCheckResults.add(healthCheckResult);
    withBadHealthCheckResults.add(badHealthCheckResult);

    taskWithOneBadHealthCheck.setHealthCheckResults(withBadHealthCheckResults);

    appResponse.getApp().getTasks().add(taskWithOneBadHealthCheck);

    ReflectionAssert.assertReflectionEquals(
            "should be two tasks",
            IntStream.of(1,2)
                .mapToObj(index ->
                        new DefaultServiceInstance(
                            "app1",
                            "host" + index,
                            9090,
                            false
                        )
                ).collect(Collectors.toList()),
            discoveryClient.getInstances("app1"),
            ReflectionComparatorMode.LENIENT_ORDER
    );
}
 
Example #10
Source File: Marathon.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@RequestLine("GET /v2/apps/{id}")
GetAppResponse getApp(@Named("id") String id) throws MarathonException;