-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JBPM-8153 Container is removed from UI even though it was not possibl…
…e to stop it. (#3452)
- Loading branch information
Showing
8 changed files
with
237 additions
and
20 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...ain/java/org/kie/workbench/common/screens/server/management/service/ContainerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2020 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.workbench.common.screens.server.management.service; | ||
|
||
import org.jboss.errai.bus.server.annotations.Remote; | ||
import org.kie.server.controller.api.model.spec.ContainerSpec; | ||
|
||
@Remote | ||
public interface ContainerService { | ||
|
||
boolean isRunningContainer(ContainerSpec containerSpec); | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
.../kie/workbench/common/screens/server/management/backend/service/ContainerServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2020 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.workbench.common.screens.server.management.backend.service; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Any; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.errai.bus.server.annotations.Service; | ||
import org.kie.server.api.model.instance.ProcessInstance; | ||
import org.kie.server.client.KieServicesClient; | ||
import org.kie.server.client.QueryServicesClient; | ||
import org.kie.server.controller.api.model.runtime.ServerInstanceKey; | ||
import org.kie.server.controller.api.model.spec.ContainerSpec; | ||
import org.kie.server.controller.api.model.spec.ServerTemplate; | ||
import org.kie.server.controller.impl.KieServerInstanceManager; | ||
import org.kie.server.controller.api.service.SpecManagementService; | ||
import org.kie.workbench.common.screens.server.management.service.ContainerService; | ||
|
||
@Service | ||
@ApplicationScoped | ||
public class ContainerServiceImpl implements ContainerService { | ||
|
||
private KieServerInstanceManager kieServerInstanceManager = KieServerInstanceManager.getInstance(); | ||
|
||
@Inject | ||
@Any | ||
private SpecManagementService specManagementService; | ||
|
||
@Override | ||
public boolean isRunningContainer(ContainerSpec containerSpec) { | ||
ServerTemplate serverTemplate = specManagementService.getServerTemplate(containerSpec.getServerTemplateKey().getId()); | ||
AtomicBoolean atomicBoolean = new AtomicBoolean(false); | ||
for (ServerInstanceKey serverInstanceKey : serverTemplate.getServerInstanceKeys()) { | ||
KieServicesClient client = kieServerInstanceManager.getClient(serverInstanceKey.getUrl()); | ||
|
||
QueryServicesClient queryServicesClient = client.getServicesClient(QueryServicesClient.class); | ||
List<ProcessInstance> processInstances = queryServicesClient.findProcessInstancesByContainerId(containerSpec.getId(), Arrays.asList(0, 1, 4), 0, 100); | ||
|
||
if (!processInstances.isEmpty()) { | ||
atomicBoolean.set(true); | ||
break; | ||
} | ||
} | ||
|
||
return atomicBoolean.get(); | ||
} | ||
|
||
protected void setKieServerInstanceManager(KieServerInstanceManager kieServerInstanceManager) { | ||
this.kieServerInstanceManager = kieServerInstanceManager; | ||
} | ||
|
||
protected void setSpecManagementService(SpecManagementService specManagementService) { | ||
this.specManagementService = specManagementService; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
.../workbench/common/screens/server/management/backend/service/ContainerServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2020 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.kie.workbench.common.screens.server.management.backend.service; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.kie.server.api.model.instance.ProcessInstance; | ||
import org.kie.server.client.KieServicesClient; | ||
import org.kie.server.client.QueryServicesClient; | ||
import org.kie.server.controller.api.model.runtime.ServerInstanceKey; | ||
import org.kie.server.controller.api.model.spec.ContainerSpec; | ||
import org.kie.server.controller.api.model.spec.ServerTemplate; | ||
import org.kie.server.controller.api.model.spec.ServerTemplateKey; | ||
import org.kie.server.controller.api.service.SpecManagementService; | ||
import org.kie.server.controller.impl.KieServerInstanceManager; | ||
import org.kie.server.controller.impl.service.SpecManagementServiceImpl; | ||
import org.kie.workbench.common.screens.server.management.service.ContainerService; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ContainerServiceImplTest { | ||
|
||
@Mock | ||
SpecManagementService specManagementService ; | ||
|
||
@Mock | ||
KieServerInstanceManager kieServerInstanceManager; | ||
|
||
private ContainerService containerService; | ||
|
||
@Before | ||
public void init() { | ||
containerService = spy(new ContainerServiceImpl()); | ||
((ContainerServiceImpl) containerService).setSpecManagementService(specManagementService); | ||
((ContainerServiceImpl) containerService).setKieServerInstanceManager(kieServerInstanceManager); | ||
} | ||
|
||
@Test | ||
public void testIsRunningContainer() { | ||
ServerTemplate serverTemplate = mock(ServerTemplate.class); | ||
doReturn(serverTemplate).when(specManagementService).getServerTemplate(any()); | ||
when(serverTemplate.getServerInstanceKeys()).thenReturn(Arrays.asList(new ServerInstanceKey("test", "test", "test", "test"))); | ||
|
||
QueryServicesClient queryServicesClient = mock(QueryServicesClient.class); | ||
KieServicesClient client = mock(KieServicesClient.class); | ||
when(kieServerInstanceManager.getClient(any())).thenReturn(client); | ||
when(client.getServicesClient(QueryServicesClient.class)).thenReturn(queryServicesClient); | ||
when(queryServicesClient.findProcessInstancesByContainerId("test", Arrays.asList(0, 1, 4), 0, 100)).thenReturn(Arrays.asList(new ProcessInstance())); | ||
boolean runningResult = containerService.isRunningContainer(new ContainerSpec("test", "", new ServerTemplateKey("1", "test"), null, null, null)); | ||
|
||
assertEquals(true, runningResult); | ||
|
||
when(queryServicesClient.findProcessInstancesByContainerId("test", Arrays.asList(0, 1, 4), 0, 100)).thenReturn(Collections.emptyList()); | ||
boolean result = containerService.isRunningContainer(new ContainerSpec("test", "", new ServerTemplateKey("1", "test"), null, null, null)); | ||
assertEquals(false, result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters