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;
}
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.");
}
}
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();
}
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);
}
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));
}
Aggregations