Search in sources :

Example 31 with ServerTemplate

use of org.kie.server.controller.api.model.spec.ServerTemplate in project kie-wb-common by kiegroup.

the class ServerTemplateVFSStorage method load.

@Override
public List<ServerTemplate> load() {
    logger.debug("About to load all available server templates...");
    final List<ServerTemplate> result = new ArrayList<ServerTemplate>();
    final Path dir = buildPath(null);
    try {
        ioService.startBatch(dir.getFileSystem());
        for (final Path registeredServer : ioService.newDirectoryStream(dir)) {
            try {
                ServerTemplate serverTemplate = readServerTemplate(registeredServer);
                logger.debug("Found server template {}", serverTemplate);
                result.add(serverTemplate);
            } catch (final Exception ignore) {
                ioService.delete(registeredServer);
            }
        }
        logger.debug("All found server templates {}", result);
        return result;
    } catch (final NotDirectoryException ignore) {
        logger.debug("No directory found {}, returning empty result", dir);
        return result;
    } finally {
        ioService.endBatch();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ArrayList(java.util.ArrayList) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException)

Example 32 with ServerTemplate

use of org.kie.server.controller.api.model.spec.ServerTemplate in project kie-wb-common by kiegroup.

the class ServerTemplateVFSStorage method loadKeys.

@Override
public List<ServerTemplateKey> loadKeys() {
    logger.debug("About to load all available server templates (as keys only)...");
    final List<ServerTemplateKey> result = new ArrayList<ServerTemplateKey>();
    final Path dir = buildPath(null);
    try {
        ioService.startBatch(dir.getFileSystem());
        for (final Path registeredServer : ioService.newDirectoryStream(dir)) {
            try {
                ServerTemplate serverTemplate = readServerTemplate(registeredServer);
                logger.debug("Found server template {}, taking its short key version...");
                result.add(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName()));
            } catch (final Exception ignore) {
                ioService.delete(registeredServer);
            }
        }
        logger.debug("All found server template keys {}", result);
        return result;
    } catch (final NotDirectoryException ignore) {
        logger.debug("No directory found {}, returning empty result", dir);
        return result;
    } finally {
        ioService.endBatch();
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) ServerTemplateKey(org.kie.server.controller.api.model.spec.ServerTemplateKey) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) ArrayList(java.util.ArrayList) NotDirectoryException(org.uberfire.java.nio.file.NotDirectoryException)

Example 33 with ServerTemplate

use of org.kie.server.controller.api.model.spec.ServerTemplate in project kie-wb-common by kiegroup.

the class ServerTemplateVFSStorage method delete.

@Override
public ServerTemplate delete(final String identifier) {
    logger.debug("About to remove server template with id {}", identifier);
    final Path path = buildPath(identifier);
    ServerTemplate serverTemplate = null;
    try {
        ioService.startBatch(path.getFileSystem());
        serverTemplate = readServerTemplate(path);
        ioService.delete(path);
    } finally {
        ioService.endBatch();
    }
    logger.debug("Server template with id {}, removed successfully", identifier);
    return serverTemplate;
}
Also used : Path(org.uberfire.java.nio.file.Path) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate)

Example 34 with ServerTemplate

use of org.kie.server.controller.api.model.spec.ServerTemplate in project kie-wb-common by kiegroup.

the class RuntimeManagementServiceCDITest method getContainersByServerInstance_returnsEmptyList_whenInstanceWithIdDoesntExistInTemplate.

@Test
public void getContainersByServerInstance_returnsEmptyList_whenInstanceWithIdDoesntExistInTemplate() {
    final String templateId = "templateId";
    final String serverInstanceId = "serverInstanceId";
    KieServerTemplateStorage templateStorageMock = mock(KieServerTemplateStorage.class);
    when(templateStorageMock.load(eq(templateId))).thenReturn(new ServerTemplate(null, null, Collections.emptyList(), Collections.emptyMap(), Collections.emptyList(), Collections.emptyList()));
    // Setup tested service
    runtimeManagementService.setTemplateStorage(templateStorageMock);
    specManagementService.setTemplateStorage(templateStorageMock);
    // Tested method
    Collection<Container> containers = runtimeManagementServiceCDI.getContainersByServerInstance(templateId, serverInstanceId);
    assertThat(containers).as("List of containers should be empty, when Server template doesn't contain server instance id").isEmpty();
}
Also used : Container(org.kie.server.controller.api.model.runtime.Container) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) KieServerTemplateStorage(org.kie.server.controller.api.storage.KieServerTemplateStorage) Test(org.junit.Test)

Example 35 with ServerTemplate

use of org.kie.server.controller.api.model.spec.ServerTemplate in project kie-wb-common by kiegroup.

the class BuildExecutor method saveContainerSpec.

private void saveContainerSpec(final String containerId, final String containerAlias, final ServerTemplate serverTemplate, final Boolean startContainer, final Map<String, String> parameters) {
    if (containerId != null && serverTemplate != null && serverTemplate.getId() != null) {
        final ContainerSpec containerSpec = makeContainerSpec(containerId, containerAlias, serverTemplate, parameters);
        specManagementService.call(aVoid -> {
            notificationEvent.fire(new NotificationEvent(ProjectEditorResources.CONSTANTS.DeploySuccessful(), NotificationEvent.NotificationType.SUCCESS));
            if (startContainer) {
                startContainer(containerSpec);
            }
        }).saveContainerSpec(serverTemplate.getId(), containerSpec);
    }
}
Also used : UnexpectedTypeException(javax.validation.UnexpectedTypeException) Arrays(java.util.Arrays) ProcessConfig(org.kie.server.controller.api.model.spec.ProcessConfig) ServerTemplate(org.kie.server.controller.api.model.spec.ServerTemplate) HasBusyIndicator(org.uberfire.ext.widgets.common.client.common.HasBusyIndicator) GAV(org.guvnor.common.services.project.model.GAV) ServerTemplateList(org.kie.server.controller.api.model.spec.ServerTemplateList) HashMap(java.util.HashMap) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) ServerTemplateKey(org.kie.server.controller.api.model.spec.ServerTemplateKey) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) Inject(javax.inject.Inject) ContainerConfig(org.kie.server.controller.api.model.spec.ContainerConfig) MergeMode(org.kie.workbench.common.screens.server.management.model.MergeMode) POM(org.guvnor.common.services.project.model.POM) CommandWithThrowableDrivenErrorCallback(org.kie.workbench.common.widgets.client.callbacks.CommandWithThrowableDrivenErrorCallback) Capability(org.kie.server.controller.api.model.spec.Capability) RuleConfig(org.kie.server.controller.api.model.spec.RuleConfig) ProjectEditorResources(org.kie.workbench.common.screens.projecteditor.client.resources.ProjectEditorResources) MavenRepositoryMetadata(org.guvnor.common.services.project.model.MavenRepositoryMetadata) Map(java.util.Map) Module(org.guvnor.common.services.project.model.Module) SpecManagementService(org.kie.workbench.common.screens.server.management.service.SpecManagementService) KieContainerStatus(org.kie.server.api.model.KieContainerStatus) BuildService(org.guvnor.common.services.project.builder.service.BuildService) Command(org.uberfire.mvp.Command) Event(javax.enterprise.event.Event) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) ContainerSpecKey(org.kie.server.controller.api.model.spec.ContainerSpecKey) Collection(java.util.Collection) Set(java.util.Set) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) Collectors(java.util.stream.Collectors) WorkspaceProjectContext(org.guvnor.common.services.project.client.context.WorkspaceProjectContext) KieScannerStatus(org.kie.server.api.model.KieScannerStatus) List(java.util.List) DeploymentMode(org.guvnor.common.services.project.service.DeploymentMode) Message(org.jboss.errai.bus.client.api.messaging.Message) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) ConflictingRepositoriesPopup(org.guvnor.common.services.project.client.repositories.ConflictingRepositoriesPopup) RuntimeStrategy(org.kie.workbench.common.screens.server.management.model.RuntimeStrategy) Caller(org.jboss.errai.common.client.api.Caller) DeploymentScreenPopupViewImpl(org.kie.workbench.common.screens.projecteditor.client.editor.DeploymentScreenPopupViewImpl) ReleaseId(org.kie.server.api.model.ReleaseId) ContainerSpec(org.kie.server.controller.api.model.spec.ContainerSpec) NotificationEvent(org.uberfire.workbench.events.NotificationEvent)

Aggregations

ServerTemplate (org.kie.server.controller.api.model.spec.ServerTemplate)61 Test (org.junit.Test)49 ContainerSpec (org.kie.server.controller.api.model.spec.ContainerSpec)24 ServerTemplateKey (org.kie.server.controller.api.model.spec.ServerTemplateKey)12 ServerInstanceKey (org.kie.server.controller.api.model.runtime.ServerInstanceKey)11 RuleConfig (org.kie.server.controller.api.model.spec.RuleConfig)10 ArrayList (java.util.ArrayList)9 Capability (org.kie.server.controller.api.model.spec.Capability)9 ContainerConfig (org.kie.server.controller.api.model.spec.ContainerConfig)9 Path (org.uberfire.java.nio.file.Path)9 ReleaseId (org.kie.server.api.model.ReleaseId)8 ProcessConfig (org.kie.server.controller.api.model.spec.ProcessConfig)8 Command (org.uberfire.mvp.Command)7 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)7 Matchers.anyString (org.mockito.Matchers.anyString)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Container (org.kie.server.controller.api.model.runtime.Container)5 ValidateExistingContainerCallback (org.kie.workbench.common.screens.projecteditor.client.editor.DeploymentScreenPopupViewImpl.ValidateExistingContainerCallback)5 ServerTemplateSelected (org.kie.workbench.common.screens.server.management.client.events.ServerTemplateSelected)5