Search in sources :

Example 1 with ContainerCardPresenter

use of org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter in project kie-wb-common by kiegroup.

the class ContainerRemoteStatusPresenter method buildContainer.

private ContainerCardPresenter buildContainer(final Container container) {
    final ContainerCardPresenter cardPresenter = cardPresenterProvider.get();
    cardPresenter.setup(container.getServerInstanceKey(), container);
    view.addCard(cardPresenter.getView().asWidget());
    return cardPresenter;
}
Also used : ContainerCardPresenter(org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter)

Example 2 with ContainerCardPresenter

use of org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter in project kie-wb-common by kiegroup.

the class ContainerRemoteStatusPresenter method onServerInstanceUpdated.

public void onServerInstanceUpdated(@Observes final ServerInstanceUpdated serverInstanceUpdated) {
    if (serverInstanceUpdated != null && serverInstanceUpdated.getServerInstance() != null) {
        final String updatedServerInstanceKey = serverInstanceUpdated.getServerInstance().getServerInstanceId();
        if (index.containsKey(updatedServerInstanceKey)) {
            final Map<String, ContainerCardPresenter> oldIndex = new HashMap<String, ContainerCardPresenter>(index.remove(updatedServerInstanceKey));
            final Map<String, ContainerCardPresenter> newIndexIndex = new HashMap<String, ContainerCardPresenter>(serverInstanceUpdated.getServerInstance().getContainers().size());
            index.put(updatedServerInstanceKey, newIndexIndex);
            for (final Container container : serverInstanceUpdated.getServerInstance().getContainers()) {
                ContainerCardPresenter presenter = oldIndex.remove(container.getContainerSpecId());
                if (!container.getStatus().equals(KieContainerStatus.STOPPED)) {
                    if (presenter != null) {
                        presenter.updateContent(serverInstanceUpdated.getServerInstance(), container);
                    } else {
                        presenter = buildContainer(container, false);
                    }
                    newIndexIndex.put(container.getContainerName(), presenter);
                }
            }
            for (final ContainerCardPresenter presenter : oldIndex.values()) {
                presenter.delete();
            }
        } else {
            for (final Container container : serverInstanceUpdated.getServerInstance().getContainers()) {
                if (containerSpec != null && container.getServerTemplateId().equals(containerSpec.getServerTemplateKey().getId()) && container.getContainerSpecId().equals(containerSpec.getId())) {
                    buildAndIndexContainer(container);
                }
            }
        }
    } else {
        logger.warn("Illegal event argument.");
    }
}
Also used : ContainerCardPresenter(org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter) Container(org.kie.server.controller.api.model.runtime.Container) HashMap(java.util.HashMap)

Example 3 with ContainerCardPresenter

use of org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter in project kie-wb-common by kiegroup.

the class ContainerRemoteStatusPresenterTest method testOnDelete.

@Test
public void testOnDelete() {
    final ContainerCardPresenter cardPresenter = mock(ContainerCardPresenter.class);
    when(cardPresenter.getView()).thenReturn(mock(ContainerCardPresenter.View.class));
    when(presenterProvider.get()).thenReturn(cardPresenter);
    final ServerInstanceKey serverInstanceKey = new ServerInstanceKey("templateId", "serverName", "serverInstanceId", "url");
    final Container container = new Container("containerSpecId", "containerName", serverInstanceKey, Collections.<Message>emptyList(), null, null);
    container.setStatus(KieContainerStatus.STARTED);
    presenter.setup(new ContainerSpec(), Collections.singletonList(container));
    verify(view).clear();
    verify(cardPresenter).setup(container.getServerInstanceKey(), container);
    verify(view).addCard(Mockito.<IsWidget>any());
    presenter.onDelete(new ServerInstanceDeleted(serverInstanceKey.getServerInstanceId()));
    verify(cardPresenter).delete();
    presenter.onDelete(new ServerInstanceDeleted("randomKey"));
    verify(cardPresenter).delete();
}
Also used : ContainerCardPresenter(org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter) Container(org.kie.server.controller.api.model.runtime.Container) ServerInstanceDeleted(org.kie.server.controller.api.model.events.ServerInstanceDeleted) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) ServerInstanceKey(org.kie.server.controller.api.model.runtime.ServerInstanceKey) Test(org.junit.Test)

Example 4 with ContainerCardPresenter

use of org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter in project kie-wb-common by kiegroup.

the class ContainerRemoteStatusPresenterTest method testOnServerInstanceUpdatedNewInstance.

@Test
public void testOnServerInstanceUpdatedNewInstance() {
    presenter = spy(new ContainerRemoteStatusPresenter(logger, view, presenterProvider));
    final ContainerCardPresenter cardPresenter = mock(ContainerCardPresenter.class);
    when(cardPresenter.getView()).thenReturn(mock(ContainerCardPresenter.View.class));
    final ContainerCardPresenter cardPresenter2 = mock(ContainerCardPresenter.class);
    when(cardPresenter2.getView()).thenReturn(mock(ContainerCardPresenter.View.class));
    final ContainerCardPresenter cardPresenter3 = mock(ContainerCardPresenter.class);
    when(cardPresenter3.getView()).thenReturn(mock(ContainerCardPresenter.View.class));
    doReturn(cardPresenter).doReturn(cardPresenter2).doReturn(cardPresenter3).when(presenterProvider).get();
    final ServerInstance serverInstance = new ServerInstance("templateId", "serverInstanceId", "serverInstanceId", "url", "1.0", Collections.<Message>emptyList(), Collections.<Container>emptyList());
    final Container existingContainer = new Container("containerToBeRemovedSpecId", "containerToBeRemovedName", serverInstance, Collections.<Message>emptyList(), null, "url");
    existingContainer.setStatus(KieContainerStatus.STARTED);
    final ServerInstance newServerInstance = new ServerInstance("templateId", "newserverInstanceId", "newserverInstanceId", "url", "1.0", Collections.<Message>emptyList(), Collections.<Container>emptyList());
    final Container newContainer = new Container("containerSpecId", "containerName", newServerInstance, Collections.<Message>emptyList(), null, "url");
    newContainer.setStatus(KieContainerStatus.STARTED);
    newServerInstance.addContainer(newContainer);
    // To check when ContainerSpec not available
    presenter.onServerInstanceUpdated(new ServerInstanceUpdated(newServerInstance));
    verify(cardPresenter, times(0)).setup(toKey(newServerInstance), newContainer);
    presenter.setup(new ContainerSpec("containerSpecId", "containerName", new ServerTemplateKey("templateId", "templateId"), new ReleaseId(), KieContainerStatus.STARTED, Collections.<Capability, ContainerConfig>emptyMap()), Arrays.asList(existingContainer));
    verify(cardPresenter).setup(toKey(serverInstance), existingContainer);
    presenter.onServerInstanceUpdated(new ServerInstanceUpdated(newServerInstance));
    // One container added
    verify(cardPresenter2).setup(toKey(newServerInstance), newContainer);
    final Container newContainer2 = new Container("containerSpecId", "containerNameX", newServerInstance, Collections.<Message>emptyList(), null, null);
    newContainer2.setStatus(KieContainerStatus.STARTED);
    newServerInstance.addContainer(newContainer2);
    // One new container added to existing server
    presenter.onServerInstanceUpdated(new ServerInstanceUpdated(newServerInstance));
    verify(cardPresenter3).setup(newContainer2.getServerInstanceKey(), newContainer2);
}
Also used : ContainerConfig(org.kie.server.controller.api.model.spec.ContainerConfig) ContainerCardPresenter(org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter) Container(org.kie.server.controller.api.model.runtime.Container) ServerTemplateKey(org.kie.server.controller.api.model.spec.ServerTemplateKey) Capability(org.kie.server.controller.api.model.spec.Capability) ServerInstanceUpdated(org.kie.server.controller.api.model.events.ServerInstanceUpdated) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) ReleaseId(org.kie.server.api.model.ReleaseId) ServerInstance(org.kie.server.controller.api.model.runtime.ServerInstance) Test(org.junit.Test)

Example 5 with ContainerCardPresenter

use of org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter in project kie-wb-common by kiegroup.

the class ContainerRemoteStatusPresenterTest method testOnServerInstanceUpdated.

@Test
public void testOnServerInstanceUpdated() {
    final ContainerCardPresenter cardPresenter = mock(ContainerCardPresenter.class);
    when(cardPresenter.getView()).thenReturn(mock(ContainerCardPresenter.View.class));
    when(presenterProvider.get()).thenReturn(cardPresenter);
    final ServerInstance serverInstance = new ServerInstance("templateId", "serverName", "serverInstanceId", "url", "1.0", Collections.<Message>emptyList(), Collections.<Container>emptyList());
    final Container container = new Container("containerSpecId", "containerName", serverInstance, Collections.<Message>emptyList(), null, null);
    container.setStatus(KieContainerStatus.STARTED);
    final Container containerToBeRemoved = new Container("containerToBeRemovedSpecId", "containerToBeRemovedName", serverInstance, Collections.<Message>emptyList(), null, null);
    containerToBeRemoved.setStatus(KieContainerStatus.STARTED);
    serverInstance.addContainer(container);
    presenter.setup(new ContainerSpec(), Arrays.asList(container, containerToBeRemoved));
    presenter.onServerInstanceUpdated(new ServerInstanceUpdated(serverInstance));
    // One container updated,  one removed
    verify(cardPresenter).updateContent(serverInstance, container);
    verify(cardPresenter).delete();
    final ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
    verify(cardPresenter, times(2)).setup(eq(container.getServerInstanceKey()), containerCaptor.capture());
    final List<Container> containers = containerCaptor.getAllValues();
    assertEquals(2, containers.size());
    assertEquals(container, containers.get(0));
    assertEquals(containerToBeRemoved, containers.get(1));
}
Also used : ContainerCardPresenter(org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter) Container(org.kie.server.controller.api.model.runtime.Container) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) ServerInstanceUpdated(org.kie.server.controller.api.model.events.ServerInstanceUpdated) ServerInstance(org.kie.server.controller.api.model.runtime.ServerInstance) Test(org.junit.Test)

Aggregations

ContainerCardPresenter (org.kie.workbench.common.screens.server.management.client.container.status.card.ContainerCardPresenter)7 Container (org.kie.server.controller.api.model.runtime.Container)5 Test (org.junit.Test)4 ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)4 ServerInstanceUpdated (org.kie.server.controller.api.model.events.ServerInstanceUpdated)3 ServerInstance (org.kie.server.controller.api.model.runtime.ServerInstance)3 HashMap (java.util.HashMap)1 ReleaseId (org.kie.server.api.model.ReleaseId)1 ServerInstanceDeleted (org.kie.server.controller.api.model.events.ServerInstanceDeleted)1 ServerInstanceKey (org.kie.server.controller.api.model.runtime.ServerInstanceKey)1 Capability (org.kie.server.controller.api.model.spec.Capability)1 ContainerConfig (org.kie.server.controller.api.model.spec.ContainerConfig)1 ServerTemplateKey (org.kie.server.controller.api.model.spec.ServerTemplateKey)1