@Test public void testInit() throws Exception { File serverStateFile = KieServerStateFileInit.init(); String serverRepo = getServerRepo(serverStateFile); String serverId = getServerId(serverStateFile); KieServerStateRepository repository = new KieServerStateFileRepository(new File(serverRepo)); KieServerState serverState = repository.load(getServerId(serverStateFile)); KieServerConfig config = serverState.getConfiguration(); assertEquals(serverRepo, config.getConfigItem(KIE_SERVER_STATE_REPO).getValue()); assertEquals(serverId, config.getConfigItem(KIE_SERVER_ID).getValue()); assertEquals(serverContainerDeployment, config.getConfigItem(KIE_SERVER_CONTAINER_DEPLOYMENT).getValue()); Iterator<KieContainerResource> containers = serverState.getContainers().iterator(); KieContainerResource exampleContainer = containers.next(); assertEquals(example, exampleContainer.getContainerId()); assertEquals(gav7.toExternalForm(), exampleContainer.getReleaseId().toExternalForm()); assertEquals(STARTED, exampleContainer.getStatus()); KieContainerResource lettersContainer = containers.next(); assertEquals(letters, lettersContainer.getContainerId()); assertEquals(gav0.toExternalForm(), lettersContainer.getReleaseId().toExternalForm()); assertEquals(STARTED, lettersContainer.getStatus()); KieContainerResource robertContainer = containers.next(); assertEquals(robert, robertContainer.getContainerId()); assertEquals(bob, robertContainer.getContainerAlias()); assertEquals(gav8.toExternalForm(), robertContainer.getReleaseId().toExternalForm()); assertEquals(STARTED, robertContainer.getStatus()); KieContainerResource testContainer = containers.next(); assertEquals(test, testContainer.getContainerId()); assertEquals(gav5.toExternalForm(), testContainer.getReleaseId().toExternalForm()); assertEquals(STARTED, testContainer.getStatus()); assertFalse(containers.hasNext()); }
public static File init() { String serverId = KieServerStateRepositoryUtils.getServerId(); String serverRepoType = StartupStrategyProvider.get().getStrategy().getRepositoryType(); KieServerEnvironment.setServerId(serverId); KieServerEnvironment.setServerName(serverId); KieServerStateRepository repository = null; File serverStateFile = KieServerStateRepositoryUtils.getStateFile(); for (KieServerStateRepository repo : serverStateRepos) { if (repo.getClass().getSimpleName().equals(serverRepoType)) { repository = repo; break; } } if (repository == null) { repository = new KieServerStateFileRepository(KieServerStateRepositoryUtils.getFileRepoDir()); logger.warn("ServiceLoader failed to initiate kie server repository: {}, fall back to KieServerStateFileRepository.", serverRepoType); } else { logger.info("Initialized with '{}' kie server repository", serverRepoType); } if (KIE_SERVER_STATE_REPO_TYPE_DEFAULT.equals(serverRepoType) && serverStateFile.exists()) { throw new IllegalStateException(String.format( "%s already exists. %s should only be used for pre-bootstrapping creation of server state file.", serverStateFile, KieServerStateFileInit.class.getSimpleName())); } KieServerState serverState = new KieServerState(); KieServerConfig config = new KieServerConfig(); Properties properties = new Properties(); properties.putAll(System.getProperties()); properties.put(KIE_SERVER_STATE_REPO, KieServerStateRepositoryUtils.getFileRepoPath()); properties.put(KIE_SERVER_ID, serverId); properties.put(KIE_SERVER_STATE_IMMUTABLE, "true"); KieServerStateRepositoryUtils.populateWithProperties(config, properties); System.setProperty(KIE_SERVER_STATE_IMMUTABLE_INIT, "true"); serverState.setConfiguration(config); Set<KieContainerResource> containers = new LinkedHashSet<>(); String serverContainerDeployment = KieServerStateRepositoryUtils.getValue(KIE_SERVER_CONTAINER_DEPLOYMENT, "KIE_SERVER_CONTAINER_DEPLOYMENT", null); Set<KieServerContainerDeployment> deployments = KieServerContainerDeployment.fromString(serverContainerDeployment); for (KieServerContainerDeployment deployment : deployments) { KieContainerResource container = new KieContainerResource( deployment.getContainerId(), new ReleaseId(deployment.getReleaseId()), KieContainerStatus.STARTED); container.setContainerAlias(deployment.getContainerAlias()); containers.add(container); } serverState.setContainers(containers); repository.store(serverId, serverState); return serverStateFile; }
KieServerStateFileInit { public static File init() { String serverId = KieServerStateRepositoryUtils.getServerId(); String serverRepoType = StartupStrategyProvider.get().getStrategy().getRepositoryType(); KieServerEnvironment.setServerId(serverId); KieServerEnvironment.setServerName(serverId); KieServerStateRepository repository = null; File serverStateFile = KieServerStateRepositoryUtils.getStateFile(); for (KieServerStateRepository repo : serverStateRepos) { if (repo.getClass().getSimpleName().equals(serverRepoType)) { repository = repo; break; } } if (repository == null) { repository = new KieServerStateFileRepository(KieServerStateRepositoryUtils.getFileRepoDir()); logger.warn("ServiceLoader failed to initiate kie server repository: {}, fall back to KieServerStateFileRepository.", serverRepoType); } else { logger.info("Initialized with '{}' kie server repository", serverRepoType); } if (KIE_SERVER_STATE_REPO_TYPE_DEFAULT.equals(serverRepoType) && serverStateFile.exists()) { throw new IllegalStateException(String.format( "%s already exists. %s should only be used for pre-bootstrapping creation of server state file.", serverStateFile, KieServerStateFileInit.class.getSimpleName())); } KieServerState serverState = new KieServerState(); KieServerConfig config = new KieServerConfig(); Properties properties = new Properties(); properties.putAll(System.getProperties()); properties.put(KIE_SERVER_STATE_REPO, KieServerStateRepositoryUtils.getFileRepoPath()); properties.put(KIE_SERVER_ID, serverId); properties.put(KIE_SERVER_STATE_IMMUTABLE, "true"); KieServerStateRepositoryUtils.populateWithProperties(config, properties); System.setProperty(KIE_SERVER_STATE_IMMUTABLE_INIT, "true"); serverState.setConfiguration(config); Set<KieContainerResource> containers = new LinkedHashSet<>(); String serverContainerDeployment = KieServerStateRepositoryUtils.getValue(KIE_SERVER_CONTAINER_DEPLOYMENT, "KIE_SERVER_CONTAINER_DEPLOYMENT", null); Set<KieServerContainerDeployment> deployments = KieServerContainerDeployment.fromString(serverContainerDeployment); for (KieServerContainerDeployment deployment : deployments) { KieContainerResource container = new KieContainerResource( deployment.getContainerId(), new ReleaseId(deployment.getReleaseId()), KieContainerStatus.STARTED); container.setContainerAlias(deployment.getContainerAlias()); containers.add(container); } serverState.setContainers(containers); repository.store(serverId, serverState); return serverStateFile; } }
KieServerStateFileInit { public static File init() { String serverId = KieServerStateRepositoryUtils.getServerId(); String serverRepoType = StartupStrategyProvider.get().getStrategy().getRepositoryType(); KieServerEnvironment.setServerId(serverId); KieServerEnvironment.setServerName(serverId); KieServerStateRepository repository = null; File serverStateFile = KieServerStateRepositoryUtils.getStateFile(); for (KieServerStateRepository repo : serverStateRepos) { if (repo.getClass().getSimpleName().equals(serverRepoType)) { repository = repo; break; } } if (repository == null) { repository = new KieServerStateFileRepository(KieServerStateRepositoryUtils.getFileRepoDir()); logger.warn("ServiceLoader failed to initiate kie server repository: {}, fall back to KieServerStateFileRepository.", serverRepoType); } else { logger.info("Initialized with '{}' kie server repository", serverRepoType); } if (KIE_SERVER_STATE_REPO_TYPE_DEFAULT.equals(serverRepoType) && serverStateFile.exists()) { throw new IllegalStateException(String.format( "%s already exists. %s should only be used for pre-bootstrapping creation of server state file.", serverStateFile, KieServerStateFileInit.class.getSimpleName())); } KieServerState serverState = new KieServerState(); KieServerConfig config = new KieServerConfig(); Properties properties = new Properties(); properties.putAll(System.getProperties()); properties.put(KIE_SERVER_STATE_REPO, KieServerStateRepositoryUtils.getFileRepoPath()); properties.put(KIE_SERVER_ID, serverId); properties.put(KIE_SERVER_STATE_IMMUTABLE, "true"); KieServerStateRepositoryUtils.populateWithProperties(config, properties); System.setProperty(KIE_SERVER_STATE_IMMUTABLE_INIT, "true"); serverState.setConfiguration(config); Set<KieContainerResource> containers = new LinkedHashSet<>(); String serverContainerDeployment = KieServerStateRepositoryUtils.getValue(KIE_SERVER_CONTAINER_DEPLOYMENT, "KIE_SERVER_CONTAINER_DEPLOYMENT", null); Set<KieServerContainerDeployment> deployments = KieServerContainerDeployment.fromString(serverContainerDeployment); for (KieServerContainerDeployment deployment : deployments) { KieContainerResource container = new KieContainerResource( deployment.getContainerId(), new ReleaseId(deployment.getReleaseId()), KieContainerStatus.STARTED); container.setContainerAlias(deployment.getContainerAlias()); containers.add(container); } serverState.setContainers(containers); repository.store(serverId, serverState); return serverStateFile; } private  KieServerStateFileInit(); }
KieServerStateFileInit { public static File init() { String serverId = KieServerStateRepositoryUtils.getServerId(); String serverRepoType = StartupStrategyProvider.get().getStrategy().getRepositoryType(); KieServerEnvironment.setServerId(serverId); KieServerEnvironment.setServerName(serverId); KieServerStateRepository repository = null; File serverStateFile = KieServerStateRepositoryUtils.getStateFile(); for (KieServerStateRepository repo : serverStateRepos) { if (repo.getClass().getSimpleName().equals(serverRepoType)) { repository = repo; break; } } if (repository == null) { repository = new KieServerStateFileRepository(KieServerStateRepositoryUtils.getFileRepoDir()); logger.warn("ServiceLoader failed to initiate kie server repository: {}, fall back to KieServerStateFileRepository.", serverRepoType); } else { logger.info("Initialized with '{}' kie server repository", serverRepoType); } if (KIE_SERVER_STATE_REPO_TYPE_DEFAULT.equals(serverRepoType) && serverStateFile.exists()) { throw new IllegalStateException(String.format( "%s already exists. %s should only be used for pre-bootstrapping creation of server state file.", serverStateFile, KieServerStateFileInit.class.getSimpleName())); } KieServerState serverState = new KieServerState(); KieServerConfig config = new KieServerConfig(); Properties properties = new Properties(); properties.putAll(System.getProperties()); properties.put(KIE_SERVER_STATE_REPO, KieServerStateRepositoryUtils.getFileRepoPath()); properties.put(KIE_SERVER_ID, serverId); properties.put(KIE_SERVER_STATE_IMMUTABLE, "true"); KieServerStateRepositoryUtils.populateWithProperties(config, properties); System.setProperty(KIE_SERVER_STATE_IMMUTABLE_INIT, "true"); serverState.setConfiguration(config); Set<KieContainerResource> containers = new LinkedHashSet<>(); String serverContainerDeployment = KieServerStateRepositoryUtils.getValue(KIE_SERVER_CONTAINER_DEPLOYMENT, "KIE_SERVER_CONTAINER_DEPLOYMENT", null); Set<KieServerContainerDeployment> deployments = KieServerContainerDeployment.fromString(serverContainerDeployment); for (KieServerContainerDeployment deployment : deployments) { KieContainerResource container = new KieContainerResource( deployment.getContainerId(), new ReleaseId(deployment.getReleaseId()), KieContainerStatus.STARTED); container.setContainerAlias(deployment.getContainerAlias()); containers.add(container); } serverState.setContainers(containers); repository.store(serverId, serverState); return serverStateFile; } private  KieServerStateFileInit(); static void main(String... args); static File init(); }
KieServerStateFileInit { public static File init() { String serverId = KieServerStateRepositoryUtils.getServerId(); String serverRepoType = StartupStrategyProvider.get().getStrategy().getRepositoryType(); KieServerEnvironment.setServerId(serverId); KieServerEnvironment.setServerName(serverId); KieServerStateRepository repository = null; File serverStateFile = KieServerStateRepositoryUtils.getStateFile(); for (KieServerStateRepository repo : serverStateRepos) { if (repo.getClass().getSimpleName().equals(serverRepoType)) { repository = repo; break; } } if (repository == null) { repository = new KieServerStateFileRepository(KieServerStateRepositoryUtils.getFileRepoDir()); logger.warn("ServiceLoader failed to initiate kie server repository: {}, fall back to KieServerStateFileRepository.", serverRepoType); } else { logger.info("Initialized with '{}' kie server repository", serverRepoType); } if (KIE_SERVER_STATE_REPO_TYPE_DEFAULT.equals(serverRepoType) && serverStateFile.exists()) { throw new IllegalStateException(String.format( "%s already exists. %s should only be used for pre-bootstrapping creation of server state file.", serverStateFile, KieServerStateFileInit.class.getSimpleName())); } KieServerState serverState = new KieServerState(); KieServerConfig config = new KieServerConfig(); Properties properties = new Properties(); properties.putAll(System.getProperties()); properties.put(KIE_SERVER_STATE_REPO, KieServerStateRepositoryUtils.getFileRepoPath()); properties.put(KIE_SERVER_ID, serverId); properties.put(KIE_SERVER_STATE_IMMUTABLE, "true"); KieServerStateRepositoryUtils.populateWithProperties(config, properties); System.setProperty(KIE_SERVER_STATE_IMMUTABLE_INIT, "true"); serverState.setConfiguration(config); Set<KieContainerResource> containers = new LinkedHashSet<>(); String serverContainerDeployment = KieServerStateRepositoryUtils.getValue(KIE_SERVER_CONTAINER_DEPLOYMENT, "KIE_SERVER_CONTAINER_DEPLOYMENT", null); Set<KieServerContainerDeployment> deployments = KieServerContainerDeployment.fromString(serverContainerDeployment); for (KieServerContainerDeployment deployment : deployments) { KieContainerResource container = new KieContainerResource( deployment.getContainerId(), new ReleaseId(deployment.getReleaseId()), KieContainerStatus.STARTED); container.setContainerAlias(deployment.getContainerAlias()); containers.add(container); } serverState.setContainers(containers); repository.store(serverId, serverState); return serverStateFile; } private  KieServerStateFileInit(); static void main(String... args); static File init();  }