Search in sources :

Example 1 with ClouderaManagerSyncCommandPollerObject

use of com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerSyncCommandPollerObject in project cloudbreak by hortonworks.

the class ClouderaManagerSyncApiCommandIdCheckerTaskTest method testCheckStatus.

@Test
public void testCheckStatus() throws ApiException, CloudbreakException {
    // GIVEN
    ClouderaManagerSyncCommandPollerObject pollerObject = new ClouderaManagerSyncCommandPollerObject(stack, apiClient, new BigDecimal(2L), COMMAND_NAME);
    given(commandRetriever.getCommandId(anyString(), any(), any())).willReturn(Optional.of(new BigDecimal(1L)));
    // WHEN
    boolean result = underTest.checkStatus(pollerObject);
    // THEN
    assertTrue(result);
}
Also used : ClouderaManagerSyncCommandPollerObject(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerSyncCommandPollerObject) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 2 with ClouderaManagerSyncCommandPollerObject

use of com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerSyncCommandPollerObject in project cloudbreak by hortonworks.

the class ClouderaManagerSyncApiCommandIdCheckerTaskTest method testCheckStatusWithRecentCommandId.

@Test
public void testCheckStatusWithRecentCommandId() throws ApiException, CloudbreakException {
    // GIVEN
    ClouderaManagerSyncCommandPollerObject pollerObject = new ClouderaManagerSyncCommandPollerObject(stack, apiClient, new BigDecimal(1L), COMMAND_NAME);
    given(commandRetriever.getCommandId(anyString(), any(), any())).willReturn(Optional.of(new BigDecimal(2L)));
    // WHEN
    boolean result = underTest.checkStatus(pollerObject);
    // THEN
    assertTrue(result);
}
Also used : ClouderaManagerSyncCommandPollerObject(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerSyncCommandPollerObject) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 3 with ClouderaManagerSyncCommandPollerObject

use of com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerSyncCommandPollerObject in project cloudbreak by hortonworks.

the class ClouderaManagerSyncApiCommandIdCheckerTaskTest method testCheckStatusWithSameRecentCommandId.

@Test
public void testCheckStatusWithSameRecentCommandId() throws ApiException, CloudbreakException {
    // GIVEN
    ClouderaManagerSyncCommandPollerObject pollerObject = new ClouderaManagerSyncCommandPollerObject(stack, apiClient, new BigDecimal(1L), COMMAND_NAME);
    given(commandRetriever.getCommandId(anyString(), any(), any())).willReturn(Optional.of(new BigDecimal(1L)));
    // WHEN
    boolean result = underTest.checkStatus(pollerObject);
    // THEN
    assertFalse(result);
}
Also used : ClouderaManagerSyncCommandPollerObject(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerSyncCommandPollerObject) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 4 with ClouderaManagerSyncCommandPollerObject

use of com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerSyncCommandPollerObject in project cloudbreak by hortonworks.

the class ClouderaManagerSyncApiCommandIdCheckerTask method checkStatus.

@Override
public boolean checkStatus(ClouderaManagerCommandPollerObject pollerObject) {
    ApiClient apiClient = pollerObject.getApiClient();
    ClustersResourceApi api = clouderaManagerApiPojoFactory.getClustersResourceApi(apiClient);
    boolean result = false;
    ClouderaManagerSyncCommandPollerObject castedObj = cast(pollerObject);
    try {
        Optional<BigDecimal> commandId = syncApiCommandRetriever.getCommandId(castedObj.getCommandName(), api, castedObj.getStack());
        if (commandId.isPresent() && !commandId.get().equals(pollerObject.getId())) {
            LOGGER.debug("Found a new latest command ID for {} command: {}", castedObj.getCommandName(), commandId);
            result = true;
        } else if (castedObj.getId() != null && castedObj.getId().equals(commandId.orElse(null))) {
            LOGGER.debug("There is a valid command ID found: {}, but that is not the " + "newest command id of {}", castedObj.getId(), castedObj.getCommandName());
        } else {
            LOGGER.debug("Not found any new commandId yet - [recent_id: {}]", castedObj.getId());
        }
    } catch (ApiException | CloudbreakException e) {
        LOGGER.debug(String.format("Exception during polling the newest %s command.", castedObj.getCommandName()), e);
        result = false;
    }
    return result;
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ClouderaManagerSyncCommandPollerObject(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerSyncCommandPollerObject) BigDecimal(java.math.BigDecimal) ApiException(com.cloudera.api.swagger.client.ApiException)

Aggregations

ClouderaManagerSyncCommandPollerObject (com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerSyncCommandPollerObject)4 BigDecimal (java.math.BigDecimal)4 Test (org.junit.jupiter.api.Test)3 ClustersResourceApi (com.cloudera.api.swagger.ClustersResourceApi)1 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiException (com.cloudera.api.swagger.client.ApiException)1 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)1