Search in sources :

Example 1 with RuntimeIdentityDto

use of org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto in project che-server by eclipse-che.

the class WorkspaceRuntimesTest method stoppingStatusIsSetWhenRuntimeAbnormallyStopping.

@Test
public void stoppingStatusIsSetWhenRuntimeAbnormallyStopping() throws Exception {
    String error = "Some kind of error happened";
    EventService localEventService = new EventService();
    WorkspaceRuntimes localRuntimes = new WorkspaceRuntimes(localEventService, ImmutableMap.of(TEST_ENVIRONMENT_TYPE, testEnvFactory), infrastructure, sharedPool, workspaceDao, dbInitializer, probeScheduler, statuses, lockService, devfileConverter, false);
    localRuntimes.init();
    RuntimeIdentityDto identity = DtoFactory.newDto(RuntimeIdentityDto.class).withWorkspaceId("workspace123").withEnvName("my-env").withOwnerId("myId");
    mockWorkspaceWithConfig(identity);
    RuntimeContext context = mockContext(identity);
    when(context.getRuntime()).thenReturn(new TestInternalRuntime(context));
    RuntimeAbnormalStoppingEvent event = new RuntimeAbnormalStoppingEvent(identity, error);
    localRuntimes.recoverOne(infrastructure, identity);
    // when
    localEventService.publish(event);
    // then
    verify(statuses).replace("workspace123", WorkspaceStatus.STOPPING);
}
Also used : RuntimeAbnormalStoppingEvent(org.eclipse.che.api.workspace.server.event.RuntimeAbnormalStoppingEvent) RuntimeIdentityDto(org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto) EventService(org.eclipse.che.api.core.notification.EventService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) Test(org.testng.annotations.Test)

Example 2 with RuntimeIdentityDto

use of org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto in project devspaces-images by redhat-developer.

the class BrokerServicePermissionFilter method doAccept.

@Override
public void doAccept(String method, Object... params) throws ForbiddenException {
    String workspaceId;
    switch(method) {
        case BROKER_STATUS_CHANGED_METHOD:
        case BROKER_RESULT_METHOD:
            RuntimeIdentityDto runtimeId = ((BrokerStatusChangedEvent) params[0]).getRuntimeId();
            if (runtimeId == null || runtimeId.getWorkspaceId() == null) {
                throw new ForbiddenException("Workspace id must be specified");
            }
            workspaceId = runtimeId.getWorkspaceId();
            break;
        default:
            throw new ForbiddenException("Unknown method is configured to be filtered.");
    }
    Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
    if (!currentSubject.hasPermission(WorkspaceDomain.DOMAIN_ID, workspaceId, WorkspaceDomain.RUN)) {
        throw new ForbiddenException("User doesn't have the required permissions to the specified workspace");
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) RuntimeIdentityDto(org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto) BrokerStatusChangedEvent(org.eclipse.che.api.workspace.shared.dto.event.BrokerStatusChangedEvent) Subject(org.eclipse.che.commons.subject.Subject)

Example 3 with RuntimeIdentityDto

use of org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto in project devspaces-images by redhat-developer.

the class WorkspaceRuntimesTest method stoppingStatusIsSetWhenRuntimeAbnormallyStopping.

@Test
public void stoppingStatusIsSetWhenRuntimeAbnormallyStopping() throws Exception {
    String error = "Some kind of error happened";
    EventService localEventService = new EventService();
    WorkspaceRuntimes localRuntimes = new WorkspaceRuntimes(localEventService, ImmutableMap.of(TEST_ENVIRONMENT_TYPE, testEnvFactory), infrastructure, sharedPool, workspaceDao, dbInitializer, probeScheduler, statuses, lockService, devfileConverter, false);
    localRuntimes.init();
    RuntimeIdentityDto identity = DtoFactory.newDto(RuntimeIdentityDto.class).withWorkspaceId("workspace123").withEnvName("my-env").withOwnerId("myId");
    mockWorkspaceWithConfig(identity);
    RuntimeContext context = mockContext(identity);
    when(context.getRuntime()).thenReturn(new TestInternalRuntime(context));
    RuntimeAbnormalStoppingEvent event = new RuntimeAbnormalStoppingEvent(identity, error);
    localRuntimes.recoverOne(infrastructure, identity);
    // when
    localEventService.publish(event);
    // then
    verify(statuses).replace("workspace123", WorkspaceStatus.STOPPING);
}
Also used : RuntimeAbnormalStoppingEvent(org.eclipse.che.api.workspace.server.event.RuntimeAbnormalStoppingEvent) RuntimeIdentityDto(org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto) EventService(org.eclipse.che.api.core.notification.EventService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) Test(org.testng.annotations.Test)

Example 4 with RuntimeIdentityDto

use of org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto in project devspaces-images by redhat-developer.

the class ErrorRuntimeLogEventLogger method onEvent.

@Override
public void onEvent(RuntimeLogEvent event) {
    if ("stderr".equalsIgnoreCase(event.getStream()) && !isNullOrEmpty(event.getText())) {
        RuntimeIdentityDto identity = event.getRuntimeId();
        LOG.error("{} error from owner=`{}` env=`{}` workspace=`{}` text=`{}` time=`{}`", event.getMachineName() != null ? "Machine `" + event.getMachineName() + "`" : "Runtime", identity.getOwnerId(), identity.getEnvName(), identity.getWorkspaceId(), event.getText(), event.getTime());
    }
}
Also used : RuntimeIdentityDto(org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto)

Example 5 with RuntimeIdentityDto

use of org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto in project che-server by eclipse-che.

the class BrokerServicePermissionFilter method doAccept.

@Override
public void doAccept(String method, Object... params) throws ForbiddenException {
    String workspaceId;
    switch(method) {
        case BROKER_STATUS_CHANGED_METHOD:
        case BROKER_RESULT_METHOD:
            RuntimeIdentityDto runtimeId = ((BrokerStatusChangedEvent) params[0]).getRuntimeId();
            if (runtimeId == null || runtimeId.getWorkspaceId() == null) {
                throw new ForbiddenException("Workspace id must be specified");
            }
            workspaceId = runtimeId.getWorkspaceId();
            break;
        default:
            throw new ForbiddenException("Unknown method is configured to be filtered.");
    }
    Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
    if (!currentSubject.hasPermission(WorkspaceDomain.DOMAIN_ID, workspaceId, WorkspaceDomain.RUN)) {
        throw new ForbiddenException("User doesn't have the required permissions to the specified workspace");
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) RuntimeIdentityDto(org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto) BrokerStatusChangedEvent(org.eclipse.che.api.workspace.shared.dto.event.BrokerStatusChangedEvent) Subject(org.eclipse.che.commons.subject.Subject)

Aggregations

RuntimeIdentityDto (org.eclipse.che.api.workspace.shared.dto.RuntimeIdentityDto)8 EventService (org.eclipse.che.api.core.notification.EventService)4 RuntimeContext (org.eclipse.che.api.workspace.server.spi.RuntimeContext)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Test (org.testng.annotations.Test)4 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 RuntimeAbnormalStoppedEvent (org.eclipse.che.api.workspace.server.event.RuntimeAbnormalStoppedEvent)2 RuntimeAbnormalStoppingEvent (org.eclipse.che.api.workspace.server.event.RuntimeAbnormalStoppingEvent)2 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)2 BrokerStatusChangedEvent (org.eclipse.che.api.workspace.shared.dto.event.BrokerStatusChangedEvent)2 Subject (org.eclipse.che.commons.subject.Subject)2