@Test public void testToState() { String tmpId = TEST_KIE_SERVER_ID + "-from-template"; KieServerState state = repo.load(TEST_KIE_SERVER_ID); ServerTemplate template = ServerTemplateConverter.fromState(state); template.setId(tmpId); template.setName(tmpId); template.getServerInstance(TEST_KIE_SERVER_ID).setServerInstanceId(tmpId); template.getServerInstance(tmpId).setServerName(tmpId); template.getServerInstance(tmpId).setServerTemplateId(tmpId); template.getContainersSpec().stream().forEach(conSpec -> { conSpec.setId(tmpId); conSpec.setContainerName(tmpId); conSpec.setServerTemplateKey(new ServerTemplateKey(tmpId, tmpId)); }); repo.create(ServerTemplateConverter.toState(template)); state = repo.load(tmpId); assertTrue(isMatching(template, state)); }
public static KieServerState toState(ServerTemplate template) { String id = template.getId(); String name = template.getName(); KieServerMode mode = template.getMode() == null ? KieServerMode.DEVELOPMENT : template.getMode(); KieServerState state = new KieServerState(); KieServerConfig config = new KieServerConfig(); Set<KieContainerResource> containers = new HashSet<>(); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_ID, id, String.class.getName())); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_SERVICES_OPENSHIFT_SERVICE_NAME, name, String.class.getName())); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_MODE, mode.name(), String.class.getName())); if (template.getServerInstance(id) != null) { config.addConfigItem(new KieServerConfigItem(KIE_SERVER_LOCATION, template.getServerInstance(id).getUrl(), String.class.getName())); } List<String> capabilities = template.getCapabilities(); for (Capability cap : Arrays.asList(Capability.values())) { switch (cap) { case PROCESS: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_JBPM_SERVER_EXT_DISABLED, "true", String.class.getName())); break; case RULE: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_DROOLS_SERVER_EXT_DISABLED, "true", String.class.getName())); break; case PLANNING: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_OPTAPLANNER_SERVER_EXT_DISABLED, "true", String.class.getName())); break; default: break; } } for (ContainerSpec conSpec : template.getContainersSpec()) { KieContainerResource conRes = new KieContainerResource(conSpec.getId(), conSpec.getReleasedId()); conRes.setContainerAlias(conSpec.getContainerName()); conRes.setStatus(conSpec.getStatus()); for (Entry<Capability, ContainerConfig> conCfgEntry : conSpec.getConfigs().entrySet()) { switch (conCfgEntry.getKey()) { case PROCESS: ProcessConfig pcfg = (ProcessConfig) conCfgEntry.getValue(); conRes.addConfigItem(new KieServerConfigItem(PCFG_KIE_BASE, pcfg.getKBase(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_KIE_SESSION, pcfg.getKSession(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_MERGE_MODE, pcfg.getMergeMode(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_RUNTIME_STRATEGY, pcfg.getRuntimeStrategy(), CAPABILITY_BPM)); break; case RULE: RuleConfig rcfg = (RuleConfig) conCfgEntry.getValue(); conRes.setScanner(new KieScannerResource(rcfg.getScannerStatus(), rcfg.getPollInterval())); break; default: break; } } containers.add(conRes); } state.setConfiguration(config); state.setContainers(containers); return state; }
ServerTemplateConverter { public static KieServerState toState(ServerTemplate template) { String id = template.getId(); String name = template.getName(); KieServerMode mode = template.getMode() == null ? KieServerMode.DEVELOPMENT : template.getMode(); KieServerState state = new KieServerState(); KieServerConfig config = new KieServerConfig(); Set<KieContainerResource> containers = new HashSet<>(); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_ID, id, String.class.getName())); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_SERVICES_OPENSHIFT_SERVICE_NAME, name, String.class.getName())); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_MODE, mode.name(), String.class.getName())); if (template.getServerInstance(id) != null) { config.addConfigItem(new KieServerConfigItem(KIE_SERVER_LOCATION, template.getServerInstance(id).getUrl(), String.class.getName())); } List<String> capabilities = template.getCapabilities(); for (Capability cap : Arrays.asList(Capability.values())) { switch (cap) { case PROCESS: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_JBPM_SERVER_EXT_DISABLED, "true", String.class.getName())); break; case RULE: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_DROOLS_SERVER_EXT_DISABLED, "true", String.class.getName())); break; case PLANNING: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_OPTAPLANNER_SERVER_EXT_DISABLED, "true", String.class.getName())); break; default: break; } } for (ContainerSpec conSpec : template.getContainersSpec()) { KieContainerResource conRes = new KieContainerResource(conSpec.getId(), conSpec.getReleasedId()); conRes.setContainerAlias(conSpec.getContainerName()); conRes.setStatus(conSpec.getStatus()); for (Entry<Capability, ContainerConfig> conCfgEntry : conSpec.getConfigs().entrySet()) { switch (conCfgEntry.getKey()) { case PROCESS: ProcessConfig pcfg = (ProcessConfig) conCfgEntry.getValue(); conRes.addConfigItem(new KieServerConfigItem(PCFG_KIE_BASE, pcfg.getKBase(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_KIE_SESSION, pcfg.getKSession(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_MERGE_MODE, pcfg.getMergeMode(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_RUNTIME_STRATEGY, pcfg.getRuntimeStrategy(), CAPABILITY_BPM)); break; case RULE: RuleConfig rcfg = (RuleConfig) conCfgEntry.getValue(); conRes.setScanner(new KieScannerResource(rcfg.getScannerStatus(), rcfg.getPollInterval())); break; default: break; } } containers.add(conRes); } state.setConfiguration(config); state.setContainers(containers); return state; } }
ServerTemplateConverter { public static KieServerState toState(ServerTemplate template) { String id = template.getId(); String name = template.getName(); KieServerMode mode = template.getMode() == null ? KieServerMode.DEVELOPMENT : template.getMode(); KieServerState state = new KieServerState(); KieServerConfig config = new KieServerConfig(); Set<KieContainerResource> containers = new HashSet<>(); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_ID, id, String.class.getName())); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_SERVICES_OPENSHIFT_SERVICE_NAME, name, String.class.getName())); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_MODE, mode.name(), String.class.getName())); if (template.getServerInstance(id) != null) { config.addConfigItem(new KieServerConfigItem(KIE_SERVER_LOCATION, template.getServerInstance(id).getUrl(), String.class.getName())); } List<String> capabilities = template.getCapabilities(); for (Capability cap : Arrays.asList(Capability.values())) { switch (cap) { case PROCESS: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_JBPM_SERVER_EXT_DISABLED, "true", String.class.getName())); break; case RULE: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_DROOLS_SERVER_EXT_DISABLED, "true", String.class.getName())); break; case PLANNING: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_OPTAPLANNER_SERVER_EXT_DISABLED, "true", String.class.getName())); break; default: break; } } for (ContainerSpec conSpec : template.getContainersSpec()) { KieContainerResource conRes = new KieContainerResource(conSpec.getId(), conSpec.getReleasedId()); conRes.setContainerAlias(conSpec.getContainerName()); conRes.setStatus(conSpec.getStatus()); for (Entry<Capability, ContainerConfig> conCfgEntry : conSpec.getConfigs().entrySet()) { switch (conCfgEntry.getKey()) { case PROCESS: ProcessConfig pcfg = (ProcessConfig) conCfgEntry.getValue(); conRes.addConfigItem(new KieServerConfigItem(PCFG_KIE_BASE, pcfg.getKBase(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_KIE_SESSION, pcfg.getKSession(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_MERGE_MODE, pcfg.getMergeMode(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_RUNTIME_STRATEGY, pcfg.getRuntimeStrategy(), CAPABILITY_BPM)); break; case RULE: RuleConfig rcfg = (RuleConfig) conCfgEntry.getValue(); conRes.setScanner(new KieScannerResource(rcfg.getScannerStatus(), rcfg.getPollInterval())); break; default: break; } } containers.add(conRes); } state.setConfiguration(config); state.setContainers(containers); return state; } private  ServerTemplateConverter(); }
ServerTemplateConverter { public static KieServerState toState(ServerTemplate template) { String id = template.getId(); String name = template.getName(); KieServerMode mode = template.getMode() == null ? KieServerMode.DEVELOPMENT : template.getMode(); KieServerState state = new KieServerState(); KieServerConfig config = new KieServerConfig(); Set<KieContainerResource> containers = new HashSet<>(); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_ID, id, String.class.getName())); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_SERVICES_OPENSHIFT_SERVICE_NAME, name, String.class.getName())); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_MODE, mode.name(), String.class.getName())); if (template.getServerInstance(id) != null) { config.addConfigItem(new KieServerConfigItem(KIE_SERVER_LOCATION, template.getServerInstance(id).getUrl(), String.class.getName())); } List<String> capabilities = template.getCapabilities(); for (Capability cap : Arrays.asList(Capability.values())) { switch (cap) { case PROCESS: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_JBPM_SERVER_EXT_DISABLED, "true", String.class.getName())); break; case RULE: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_DROOLS_SERVER_EXT_DISABLED, "true", String.class.getName())); break; case PLANNING: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_OPTAPLANNER_SERVER_EXT_DISABLED, "true", String.class.getName())); break; default: break; } } for (ContainerSpec conSpec : template.getContainersSpec()) { KieContainerResource conRes = new KieContainerResource(conSpec.getId(), conSpec.getReleasedId()); conRes.setContainerAlias(conSpec.getContainerName()); conRes.setStatus(conSpec.getStatus()); for (Entry<Capability, ContainerConfig> conCfgEntry : conSpec.getConfigs().entrySet()) { switch (conCfgEntry.getKey()) { case PROCESS: ProcessConfig pcfg = (ProcessConfig) conCfgEntry.getValue(); conRes.addConfigItem(new KieServerConfigItem(PCFG_KIE_BASE, pcfg.getKBase(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_KIE_SESSION, pcfg.getKSession(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_MERGE_MODE, pcfg.getMergeMode(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_RUNTIME_STRATEGY, pcfg.getRuntimeStrategy(), CAPABILITY_BPM)); break; case RULE: RuleConfig rcfg = (RuleConfig) conCfgEntry.getValue(); conRes.setScanner(new KieScannerResource(rcfg.getScannerStatus(), rcfg.getPollInterval())); break; default: break; } } containers.add(conRes); } state.setConfiguration(config); state.setContainers(containers); return state; } private  ServerTemplateConverter(); static ServerTemplate fromState(KieServerState state); static KieServerState toState(ServerTemplate template); }
ServerTemplateConverter { public static KieServerState toState(ServerTemplate template) { String id = template.getId(); String name = template.getName(); KieServerMode mode = template.getMode() == null ? KieServerMode.DEVELOPMENT : template.getMode(); KieServerState state = new KieServerState(); KieServerConfig config = new KieServerConfig(); Set<KieContainerResource> containers = new HashSet<>(); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_ID, id, String.class.getName())); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_SERVICES_OPENSHIFT_SERVICE_NAME, name, String.class.getName())); config.addConfigItem(new KieServerConfigItem(KIE_SERVER_MODE, mode.name(), String.class.getName())); if (template.getServerInstance(id) != null) { config.addConfigItem(new KieServerConfigItem(KIE_SERVER_LOCATION, template.getServerInstance(id).getUrl(), String.class.getName())); } List<String> capabilities = template.getCapabilities(); for (Capability cap : Arrays.asList(Capability.values())) { switch (cap) { case PROCESS: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_JBPM_SERVER_EXT_DISABLED, "true", String.class.getName())); break; case RULE: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_DROOLS_SERVER_EXT_DISABLED, "true", String.class.getName())); break; case PLANNING: if (!capabilities.contains(cap.name())) config.addConfigItem( new KieServerConfigItem(KIE_OPTAPLANNER_SERVER_EXT_DISABLED, "true", String.class.getName())); break; default: break; } } for (ContainerSpec conSpec : template.getContainersSpec()) { KieContainerResource conRes = new KieContainerResource(conSpec.getId(), conSpec.getReleasedId()); conRes.setContainerAlias(conSpec.getContainerName()); conRes.setStatus(conSpec.getStatus()); for (Entry<Capability, ContainerConfig> conCfgEntry : conSpec.getConfigs().entrySet()) { switch (conCfgEntry.getKey()) { case PROCESS: ProcessConfig pcfg = (ProcessConfig) conCfgEntry.getValue(); conRes.addConfigItem(new KieServerConfigItem(PCFG_KIE_BASE, pcfg.getKBase(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_KIE_SESSION, pcfg.getKSession(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_MERGE_MODE, pcfg.getMergeMode(), CAPABILITY_BPM)); conRes.addConfigItem(new KieServerConfigItem(PCFG_RUNTIME_STRATEGY, pcfg.getRuntimeStrategy(), CAPABILITY_BPM)); break; case RULE: RuleConfig rcfg = (RuleConfig) conCfgEntry.getValue(); conRes.setScanner(new KieScannerResource(rcfg.getScannerStatus(), rcfg.getPollInterval())); break; default: break; } } containers.add(conRes); } state.setConfiguration(config); state.setContainers(containers); return state; } private  ServerTemplateConverter(); static ServerTemplate fromState(KieServerState state); static KieServerState toState(ServerTemplate template);  }