Search in sources :

Example 1 with StructuredEventContainer

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

the class EventV4Controller method download.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.POWERUSER_ONLY)
public Response download(String name, @AccountId String accountId) {
    StructuredEventContainer events = legacyStructuredEventService.getStructuredEventsForStack(name, workspaceService.getForCurrentUser().getId());
    StreamingOutput streamingOutput = output -> {
        try (ZipOutputStream zipOutputStream = new ZipOutputStream(output)) {
            zipOutputStream.putNextEntry(new ZipEntry("struct-events.json"));
            zipOutputStream.write(JsonUtil.writeValueAsString(events).getBytes());
            zipOutputStream.closeEntry();
        }
    };
    return Response.ok(streamingOutput).header("content-disposition", "attachment; filename = struct-events.zip").build();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) WorkspaceEntityType(com.sequenceiq.cloudbreak.workspace.controller.WorkspaceEntityType) StructuredEventEntity(com.sequenceiq.cloudbreak.domain.StructuredEventEntity) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Controller(org.springframework.stereotype.Controller) Inject(javax.inject.Inject) AccountId(com.sequenceiq.cloudbreak.auth.security.internal.AccountId) LegacyStructuredEventService(com.sequenceiq.cloudbreak.structuredevent.LegacyStructuredEventService) Sort(org.springframework.data.domain.Sort) CloudbreakEventV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.events.responses.CloudbreakEventV4Responses) ZipEntry(java.util.zip.ZipEntry) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) TxType(javax.transaction.Transactional.TxType) Transactional(javax.transaction.Transactional) PageRequest(org.springframework.data.domain.PageRequest) WorkspaceService(com.sequenceiq.cloudbreak.service.workspace.WorkspaceService) StreamingOutput(javax.ws.rs.core.StreamingOutput) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount) Page(org.springframework.data.domain.Page) EventV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.events.EventV4Endpoint) List(java.util.List) Response(javax.ws.rs.core.Response) CloudbreakEventsFacade(com.sequenceiq.cloudbreak.facade.CloudbreakEventsFacade) StructuredEventContainer(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventContainer) Optional(java.util.Optional) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) TenantAwareParam(com.sequenceiq.cloudbreak.auth.security.internal.TenantAwareParam) CloudbreakEventV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.events.responses.CloudbreakEventV4Response) ZipOutputStream(java.util.zip.ZipOutputStream) StructuredEventContainer(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventContainer) ZipEntry(java.util.zip.ZipEntry) StreamingOutput(javax.ws.rs.core.StreamingOutput) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 2 with StructuredEventContainer

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

the class DistroxStopStartScaleDurationAssertions method doAssertion.

@Override
public DistroXTestDto doAssertion(TestContext testContext, DistroXTestDto testDto, CloudbreakClient client) throws Exception {
    String startMessage = scalingUp ? "Scaling up (via instance start) for host group" : "Scaling down (via instance stop) for host group";
    String stopMessage = scalingUp ? "Scaled up (via instance start) host group" : "Scaled down (via instance stop) host group";
    StructuredEventContainer structuredEventContainer = client.getDefaultClient().eventV4Endpoint().structured(testDto.getName(), testContext.getActingUserCrn().getAccountId());
    List<StructuredNotificationEvent> structuredNotificationEvents = structuredEventContainer.getNotification();
    long startTime = getTimestampForEvent(structuredNotificationEvents, startMessage);
    long endTime = getTimestampForEvent(structuredNotificationEvents, stopMessage);
    long actualDuration = endTime - startTime;
    LOGGER.info(String.format("[%s] event duration '%s' minutes.", startMessage, TimeUnit.MILLISECONDS.toMinutes(actualDuration)));
    String message = String.format("Distrox last scale have been took (%d) more than the expected %d minutes!", TimeUnit.MILLISECONDS.toMinutes(actualDuration), expectedDuration);
    if (actualDuration > TimeUnit.MINUTES.toMillis(expectedDuration)) {
        LOGGER.error(message);
        throw new TestFailException(message);
    }
    return testDto;
}
Also used : StructuredEventContainer(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventContainer) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) StructuredNotificationEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent)

Aggregations

StructuredEventContainer (com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventContainer)2 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)1 AuthorizationResourceAction (com.sequenceiq.authorization.resource.AuthorizationResourceAction)1 EventV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.events.EventV4Endpoint)1 CloudbreakEventV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.events.responses.CloudbreakEventV4Response)1 CloudbreakEventV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.events.responses.CloudbreakEventV4Responses)1 AccountId (com.sequenceiq.cloudbreak.auth.security.internal.AccountId)1 TenantAwareParam (com.sequenceiq.cloudbreak.auth.security.internal.TenantAwareParam)1 NotFoundException.notFound (com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound)1 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)1 StructuredEventEntity (com.sequenceiq.cloudbreak.domain.StructuredEventEntity)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1 CloudbreakEventsFacade (com.sequenceiq.cloudbreak.facade.CloudbreakEventsFacade)1 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)1 WorkspaceService (com.sequenceiq.cloudbreak.service.workspace.WorkspaceService)1 LegacyStructuredEventService (com.sequenceiq.cloudbreak.structuredevent.LegacyStructuredEventService)1 StructuredNotificationEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredNotificationEvent)1 WorkspaceEntityType (com.sequenceiq.cloudbreak.workspace.controller.WorkspaceEntityType)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 List (java.util.List)1