Search in sources :

Example 56 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class RestCDPEventDataExtractor method eventData.

@Override
public EventData eventData(CDPStructuredRestCallEvent structuredEvent) {
    RestRequestDetails restRequest = structuredEvent.getRestCall().getRestRequest();
    boolean mutating = Set.of("POST", "PUT", "DELETE").contains(restRequest.getMethod());
    String userAgent = restRequest.getHeaders().get("user-agent");
    Map<String, Object> requestParameters = new HashMap<>();
    requestParameters.put("uri", restRequest.getRequestUri());
    String resourceType = structuredEvent.getOperation().getResourceType();
    CDPRestResourceAuditEventConverter restResourceAuditEventConverter = getConverter(resourceType);
    if (restResourceAuditEventConverter != null) {
        LOGGER.info("Determine request params with {}", restResourceAuditEventConverter);
        Map<String, String> params = restResourceAuditEventConverter.requestParameters(structuredEvent);
        requestParameters.putAll(params);
    }
    return ApiRequestData.builder().withApiVersion(cbVersion).withMutating(mutating).withRequestParameters(new Json(requestParameters).getValue()).withUserAgent(userAgent).build();
}
Also used : HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Json(com.sequenceiq.cloudbreak.common.json.Json) CDPRestResourceAuditEventConverter(com.sequenceiq.cloudbreak.structuredevent.service.audit.auditeventname.rest.CDPRestResourceAuditEventConverter)

Example 57 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class StackDownscaleServiceTest method finishStackDownscaleAndDontSaveVolumeFQDNTest.

@Test
public void finishStackDownscaleAndDontSaveVolumeFQDNTest() throws TransactionService.TransactionExecutionException {
    StackScalingFlowContext stackScalingFlowContext = mock(StackScalingFlowContext.class);
    Stack stack = mock(Stack.class);
    when(stackScalingFlowContext.getStack()).thenReturn(stack);
    when(stackScalingFlowContext.isRepair()).thenReturn(true);
    InstanceGroup masterGroup = new InstanceGroup();
    masterGroup.setGroupName("master");
    when(stack.getInstanceGroups()).thenReturn(Set.of(masterGroup));
    InstanceMetaData master = new InstanceMetaData();
    master.setInstanceId("i-1111");
    master.setPrivateId(1L);
    master.setDiscoveryFQDN("master1.cloudera.site");
    masterGroup.setInstanceMetaData(Set.of(master));
    ArrayList<Resource> volumes = new ArrayList<>();
    Resource volume1 = new Resource();
    volumes.add(volume1);
    volume1.setInstanceId("i-1111");
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az1", false, "", new ArrayList<>(), 50, "gp2");
    volumeSetAttributes.setDiscoveryFQDN("some.fqdn");
    volume1.setAttributes(Json.silent(volumeSetAttributes));
    doReturn(Optional.of(volumeSetAttributes)).when(resourceAttributeUtil).getTypedAttributes(volume1, VolumeSetAttributes.class);
    when(resourceService.findByStackIdAndType(any(), any())).thenReturn(volumes);
    stackDownscaleService.finishStackDownscale(stackScalingFlowContext, Set.of(1L));
    verify(resourceService).saveAll(resourcesCaptor.capture());
    Iterable<Resource> resourcesCaptorValue = resourcesCaptor.getValue();
    Json attributes = resourcesCaptorValue.iterator().next().getAttributes();
    assertEquals("some.fqdn", attributes.getValue("discoveryFQDN"));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Resource(com.sequenceiq.cloudbreak.domain.Resource) ArrayList(java.util.ArrayList) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test)

Example 58 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class StackDownscaleServiceTest method finishStackDownscaleAndSaveVolumeFQDNTest.

@Test
public void finishStackDownscaleAndSaveVolumeFQDNTest() throws TransactionService.TransactionExecutionException {
    StackScalingFlowContext stackScalingFlowContext = mock(StackScalingFlowContext.class);
    Stack stack = mock(Stack.class);
    when(stackScalingFlowContext.getStack()).thenReturn(stack);
    when(stackScalingFlowContext.isRepair()).thenReturn(true);
    InstanceGroup masterGroup = new InstanceGroup();
    masterGroup.setGroupName("master");
    when(stack.getInstanceGroups()).thenReturn(Set.of(masterGroup));
    InstanceMetaData master = new InstanceMetaData();
    master.setInstanceId("i-1111");
    master.setDiscoveryFQDN("master1.cloudera.site");
    master.setPrivateId(1L);
    masterGroup.setInstanceMetaData(Set.of(master));
    ArrayList<Resource> volumes = new ArrayList<>();
    Resource volume1 = new Resource();
    volumes.add(volume1);
    volume1.setInstanceId("i-1111");
    doReturn(Optional.of(new VolumeSetAttributes("az1", false, "", new ArrayList<>(), 50, "gp2"))).when(resourceAttributeUtil).getTypedAttributes(volume1, VolumeSetAttributes.class);
    when(resourceService.findByStackIdAndType(any(), any())).thenReturn(volumes);
    stackDownscaleService.finishStackDownscale(stackScalingFlowContext, Set.of(1L));
    verify(resourceService).saveAll(resourcesCaptor.capture());
    Iterable<Resource> resourcesCaptorValue = resourcesCaptor.getValue();
    Json attributes = resourcesCaptorValue.iterator().next().getAttributes();
    assertEquals("master1.cloudera.site", attributes.getValue("discoveryFQDN"));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Resource(com.sequenceiq.cloudbreak.domain.Resource) ArrayList(java.util.ArrayList) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test)

Example 59 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class PackageVersionCheckerTest method compareImageAndInstancesMandatoryPackageVersionPrewarmedOk.

@Test
public void compareImageAndInstancesMandatoryPackageVersionPrewarmedOk() throws JsonProcessingException {
    String packageName = "package";
    Map<String, String> packageVersions = Collections.singletonMap(packageName, "1");
    when(statedImage.getImage()).thenReturn(image);
    when(image.isPrewarmed()).thenReturn(true);
    when(image.getPackageVersions()).thenReturn(packageVersions);
    Package aPackage = new Package();
    aPackage.setName(packageName);
    aPackage.setPrewarmed(true);
    when(instanceMetadataUpdater.getPackages()).thenReturn(Collections.singletonList(aPackage));
    when(instanceMetadataUpdater.isPackagesVersionEqual(anyString(), anyString())).thenReturn(true);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setImage(new Json(new com.sequenceiq.cloudbreak.cloud.model.Image("image", Collections.emptyMap(), "os", "ostype", "catalogn", "catalogu", "id", packageVersions)));
    Set<InstanceMetaData> instanceMetaDataSet = Collections.singleton(instanceMetaData);
    CheckResult result = underTest.compareImageAndInstancesMandatoryPackageVersion(statedImage, instanceMetaDataSet);
    assertEquals(EventStatus.OK, result.getStatus());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Package(com.sequenceiq.cloudbreak.service.cluster.Package) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.Test)

Example 60 with Json

use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.

the class PackageVersionCheckerTest method compareImageAndInstancesMandatoryPackageVersionDifferentPackageVersionInImage.

@Test
public void compareImageAndInstancesMandatoryPackageVersionDifferentPackageVersionInImage() throws JsonProcessingException {
    String packageName = "package";
    Map<String, String> packageVersions = Collections.singletonMap(packageName, "1");
    when(statedImage.getImage()).thenReturn(image);
    when(image.isPrewarmed()).thenReturn(true);
    when(image.getPackageVersions()).thenReturn(Collections.singletonMap(packageName, "2"));
    Package aPackage = new Package();
    aPackage.setName(packageName);
    aPackage.setPrewarmed(true);
    when(instanceMetadataUpdater.getPackages()).thenReturn(Collections.singletonList(aPackage));
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setImage(new Json(new com.sequenceiq.cloudbreak.cloud.model.Image("image", Collections.emptyMap(), "os", "ostype", "catalogn", "catalogu", "id", packageVersions)));
    Set<InstanceMetaData> instanceMetaDataSet = Collections.singleton(instanceMetaData);
    CheckResult result = underTest.compareImageAndInstancesMandatoryPackageVersion(statedImage, instanceMetaDataSet);
    assertEquals(EventStatus.FAILED, result.getStatus());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Package(com.sequenceiq.cloudbreak.service.cluster.Package) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.Test)

Aggregations

Json (com.sequenceiq.cloudbreak.common.json.Json)266 Test (org.junit.jupiter.api.Test)95 HashMap (java.util.HashMap)49 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)31 Template (com.sequenceiq.freeipa.entity.Template)26 AwsInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AwsInstanceTemplate)25 List (java.util.List)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)24 AzureInstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceTemplate)23 Map (java.util.Map)22 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)21 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)21 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)21 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)20 IOException (java.io.IOException)20 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)18 RestRequestDetails (com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails)16 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)16 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)14