Search in sources :

Example 21 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.

the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackFoundAndScaling.

@Test
public void testRequestParametersWhenStackFoundAndScaling() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    operation.setResourceName("name");
    operation.setWorkspaceId(123L);
    operation.setResourceEvent("scaling");
    event.setOperation(operation);
    RestCallDetails restCall = new RestCallDetails();
    event.setRestCall(restCall);
    RestRequestDetails restRequest = new RestRequestDetails();
    restRequest.setMethod("PUT");
    restRequest.setBody(new Json(Map.of("group", "gr", "desiredCount", 2)).getValue());
    restCall.setRestRequest(restRequest);
    Stack stack = new Stack();
    Cluster cluster = new Cluster();
    cluster.setId(345L);
    stack.setCluster(cluster);
    HostGroup hostGroup = new HostGroup();
    InstanceGroup instanceGroup = new InstanceGroup();
    hostGroup.setInstanceGroup(instanceGroup);
    Map<String, Object> params = new HashMap<>();
    when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
    when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.of(stack));
    when(hostGroupService.getByClusterIdAndNameWithRecipes(345L, "gr")).thenReturn(hostGroup);
    Map<String, Object> actual = underTest.requestParameters(event);
    Assertions.assertEquals(3, actual.size());
    Assertions.assertEquals(2, actual.get("desiredCount"));
    Assertions.assertEquals(0, actual.get("originalCount"));
    Assertions.assertEquals("gr", actual.get("hostGroup"));
}
Also used : HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) Test(org.junit.jupiter.api.Test)

Example 22 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.

the class KafkaStructuredEventHandlerTest method createDummyStructuredRestEvent.

private StructuredRestCallEvent createDummyStructuredRestEvent() {
    RestRequestDetails requestDetails = new RestRequestDetails();
    requestDetails.setBody("RequestBodyContent");
    requestDetails.setRequestUri("/v3/clusters");
    RestResponseDetails restResponseDetails = new RestResponseDetails();
    restResponseDetails.setStatusCode(200);
    restResponseDetails.setBody("BodyContent");
    restResponseDetails.setHeaders(ImmutableMap.of("content-length", "89"));
    RestCallDetails restCallDetails = new RestCallDetails();
    restCallDetails.setRestRequest(requestDetails);
    restCallDetails.setRestResponse(restResponseDetails);
    StructuredRestCallEvent restEvent = new StructuredRestCallEvent();
    restEvent.setRestCall(restCallDetails);
    restEvent.setType("StructuredRestCallEvent");
    return restEvent;
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) RestResponseDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)

Example 23 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.

the class KafkaStructuredEventHandlerTest method checkIfPropertiesGetFilteredWithCustomMapper.

@Test
public void checkIfPropertiesGetFilteredWithCustomMapper() {
    StructuredRestCallEvent restEvent = createDummyStructuredRestEvent();
    classIntest.sanitizeSensitiveRestData(restEvent);
    RestRequestDetails requestDetails = restEvent.getRestCall().getRestRequest();
    assertTrue("Should be sanitized from Kafka event", requestDetails.getBody().contains(REPLACEMENT));
    assertTrue("Should be empty because of ", requestDetails.getHeaders().isEmpty());
    assertTrue("Should be left intact", requestDetails.getRequestUri().equals("/v3/clusters"));
}
Also used : StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Test(org.junit.Test)

Example 24 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.

the class FreeIpaCustomCrnOrNameProviderTest method testProviderWhenHasQueryParamsAndContainsEnvironmentCrn.

@Test
public void testProviderWhenHasQueryParamsAndContainsEnvironmentCrn() {
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails restRequestDetails = new RestRequestDetails();
    restCallDetails.setRestRequest(restRequestDetails);
    restRequestDetails.setRequestUri("http://localhost/any/path?environment=env-crn");
    String userCrn = CrnTestUtil.getUserCrnBuilder().setAccountId("acc").setResource("res").build().toString();
    Stack stack = new Stack();
    stack.setName("stackName");
    stack.setResourceCrn("stackCrn");
    stack.setId(2922L);
    when(stackService.findMultipleByEnvironmentCrnAndAccountIdEvenIfTerminated("env-crn", "acc")).thenReturn(List.of(stack));
    Map<String, String> restParams = new HashMap<>();
    Map<String, String> expected = ThreadBasedUserCrnProvider.doAs(userCrn, () -> underTest.provide(restCallDetails, null, restParams, "name", "crn"));
    Assertions.assertEquals("stackName", expected.get("name"));
    Assertions.assertEquals("stackCrn", expected.get("crn"));
    Assertions.assertEquals("2922", expected.get(RESOURCE_ID));
}
Also used : RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 25 with RestRequestDetails

use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.

the class FreeIpaCustomCrnOrNameProviderTest method testProviderWhenNoQueryParams.

@Test
public void testProviderWhenNoQueryParams() {
    RestCallDetails restCallDetails = new RestCallDetails();
    RestRequestDetails restRequestDetails = new RestRequestDetails();
    restCallDetails.setRestRequest(restRequestDetails);
    restRequestDetails.setRequestUri("http://localhost/any/path");
    Map<String, String> restParams = new HashMap<>();
    underTest.provide(restCallDetails, null, restParams, "name", "crn");
    Assertions.assertFalse(restParams.containsKey("name"));
    Assertions.assertFalse(restParams.containsKey("crn"));
}
Also used : RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Test(org.junit.jupiter.api.Test)

Aggregations

RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)40 HashMap (java.util.HashMap)29 RestResponseDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestResponseDetails)25 Test (org.junit.jupiter.api.Test)23 RestCallDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails)20 Json (com.sequenceiq.cloudbreak.common.json.Json)15 StructuredRestCallEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent)11 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails)8 Map (java.util.Map)6 OutputStream (java.io.OutputStream)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FilterOutputStream (java.io.FilterOutputStream)2 Entry (java.util.Map.Entry)2 MediaType (javax.ws.rs.core.MediaType)2 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)1 RestResourceAuditEventConverter (com.sequenceiq.cloudbreak.structuredevent.auditeventname.rest.RestResourceAuditEventConverter)1