Search in sources :

Example 6 with ApiEvent

use of com.cloudera.api.swagger.model.ApiEvent in project knox by apache.

the class PollingConfigurationAnalyzerTest method testRestartEventWithConfigChange.

/**
 * Test the restart of an existing service when relevant configuration has changed.
 */
@Test
public void testRestartEventWithConfigChange() {
    final String clusterName = "Cluster 2";
    // Simulate a service restart event
    ApiEvent restartEvent = createApiEvent(clusterName, NameNodeServiceModelGenerator.SERVICE_TYPE, NameNodeServiceModelGenerator.SERVICE, PollingConfigurationAnalyzer.RESTART_COMMAND, PollingConfigurationAnalyzer.SUCCEEDED_STATUS);
    doTestEventWithConfigChange(restartEvent, clusterName);
}
Also used : ApiEvent(com.cloudera.api.swagger.model.ApiEvent) Test(org.junit.Test)

Example 7 with ApiEvent

use of com.cloudera.api.swagger.model.ApiEvent in project knox by apache.

the class PollingConfigurationAnalyzerTest method testRestartEventWithoutConfigChange.

/**
 * Test the restart of an existing service when no relevant configuration has changed.
 */
@Test
public void testRestartEventWithoutConfigChange() {
    final String clusterName = "Cluster 2";
    // Simulate a service restart event
    ApiEvent restartEvent = createApiEvent(clusterName, NameNodeServiceModelGenerator.SERVICE_TYPE, NameNodeServiceModelGenerator.SERVICE, PollingConfigurationAnalyzer.RESTART_COMMAND, PollingConfigurationAnalyzer.SUCCEEDED_STATUS);
    doTestEventWithoutConfigChange(restartEvent, clusterName);
}
Also used : ApiEvent(com.cloudera.api.swagger.model.ApiEvent) Test(org.junit.Test)

Example 8 with ApiEvent

use of com.cloudera.api.swagger.model.ApiEvent in project knox by apache.

the class PollingConfigurationAnalyzerTest method testRollingServiceRestartWithConfigChange.

/**
 * Test the rolling restart of an existing service when relevant configuration has changed.
 */
@Test
public void testRollingServiceRestartWithConfigChange() {
    final String clusterName = "Cluster 1";
    // Simulate a successful rolling service restart event
    ApiEvent rollingRestartEvent = createApiEvent(clusterName, NameNodeServiceModelGenerator.SERVICE_TYPE, NameNodeServiceModelGenerator.SERVICE, PollingConfigurationAnalyzer.ROLLING_RESTART_COMMAND, PollingConfigurationAnalyzer.SUCCEEDED_STATUS, "EV_SERVICE_ROLLING_RESTARTED");
    doTestEventWithConfigChange(rollingRestartEvent, clusterName);
}
Also used : ApiEvent(com.cloudera.api.swagger.model.ApiEvent) Test(org.junit.Test)

Example 9 with ApiEvent

use of com.cloudera.api.swagger.model.ApiEvent in project knox by apache.

the class PollingConfigurationAnalyzer method queryEvents.

/**
 * Query the ClouderaManager instance associated with the specified client for any service start events in the
 * specified cluster since the specified time.
 *
 * @param client      A ClouderaManager API client.
 * @param clusterName The name of the cluster for which events should be queried.
 * @param since       The ISO8601 timestamp indicating from which time to query.
 *
 * @return A List of ApiEvent objects representing the relevant events since the specified time.
 */
protected List<ApiEvent> queryEvents(final ApiClient client, final String clusterName, final String since) {
    List<ApiEvent> events = new ArrayList<>();
    // Setup the query for events
    String timeFilter = (since != null) ? String.format(Locale.ROOT, EVENTS_QUERY_TIMESTAMP_FORMAT, since) : "";
    String queryString = String.format(Locale.ROOT, EVENTS_QUERY_FORMAT, clusterName, timeFilter);
    try {
        // giving 'null' as maximum result size results in fetching all events from CM within the given time interval
        ApiEventQueryResult eventsResult = (new EventsResourceApi(client)).readEvents(null, queryString, 0);
        events.addAll(eventsResult.getItems());
    } catch (ApiException e) {
        log.clouderaManagerEventsAPIError(e);
    }
    return events;
}
Also used : ApiEvent(com.cloudera.api.swagger.model.ApiEvent) ArrayList(java.util.ArrayList) ApiEventQueryResult(com.cloudera.api.swagger.model.ApiEventQueryResult) EventsResourceApi(com.cloudera.api.swagger.EventsResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 10 with ApiEvent

use of com.cloudera.api.swagger.model.ApiEvent in project knox by apache.

the class PollingConfigurationAnalyzerTest method testRestartWaitingForStalenessSuccessEventProcessedOnlyOnce.

@Test
public void testRestartWaitingForStalenessSuccessEventProcessedOnlyOnce() {
    final String address = "http://host1:1234";
    final String clusterName = "Cluster 9";
    // Simulate a successful restart waiting for staleness event with id = 123
    final ApiEvent rollingRestartEvent = createApiEvent(clusterName, PollingConfigurationAnalyzer.CM_SERVICE_TYPE, PollingConfigurationAnalyzer.CM_SERVICE, PollingConfigurationAnalyzer.RESTART_WAITING_FOR_STALENESS_SUCCESS_COMMAND, PollingConfigurationAnalyzer.SUCCEEDED_STATUS, "EV_CLUSTER_RESTARTED", "123");
    final ChangeListener listener = new ChangeListener();
    final TestablePollingConfigAnalyzer pca = buildPollingConfigAnalyzer(address, clusterName, Collections.emptyMap(), listener);
    // this should trigger a change notification
    doTestEvent(rollingRestartEvent, address, clusterName, Collections.emptyMap(), Collections.emptyMap(), pca);
    assertTrue("Expected a change notification", listener.wasNotified(address, clusterName));
    // this should NOT trigger a notification as the same event has already been processed
    listener.clearNotification();
    doTestEvent(rollingRestartEvent, address, clusterName, Collections.emptyMap(), Collections.emptyMap(), pca);
    assertFalse("Unexpected change notification", listener.wasNotified(address, clusterName));
}
Also used : ApiEvent(com.cloudera.api.swagger.model.ApiEvent) ConfigurationChangeListener(org.apache.knox.gateway.topology.discovery.ClusterConfigurationMonitor.ConfigurationChangeListener) Test(org.junit.Test)

Aggregations

ApiEvent (com.cloudera.api.swagger.model.ApiEvent)15 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)4 ConfigurationChangeListener (org.apache.knox.gateway.topology.discovery.ClusterConfigurationMonitor.ConfigurationChangeListener)4 ApiEventAttribute (com.cloudera.api.swagger.model.ApiEventAttribute)2 EventsResourceApi (com.cloudera.api.swagger.EventsResourceApi)1 ApiException (com.cloudera.api.swagger.client.ApiException)1 ApiEventQueryResult (com.cloudera.api.swagger.model.ApiEventQueryResult)1 Instant (java.time.Instant)1