Java Code Examples for mesosphere.marathon.client.model.v2.GetAppResponse#setApp()

The following examples show how to use mesosphere.marathon.client.model.v2.GetAppResponse#setApp() . 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: 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 2
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 3
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 4
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 5
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
    );
}