/** * Creates a CLI script for adding virtual-server to AS7 * * @param virtualServer object representing migrated virtual-server * @return string containing created CLI script * @deprecated Generate this from the ModelNode. */ private static String createVirtualServerScript(VirtualServerBean virtualServer) throws CliScriptException { String errMsg = "in virtual-server (engine in AS5) must be set"; Utils.throwIfBlank(virtualServer.getVirtualServerName(), errMsg, "Server name"); CliAddScriptBuilder builder = new CliAddScriptBuilder(); StringBuilder resultScript = new StringBuilder("/subsystem=web/virtual-server="); resultScript.append(virtualServer.getVirtualServerName()).append(":add("); builder.addProperty("enable-welcome-root", virtualServer.getEnableWelcomeRoot()); builder.addProperty("default-web-module", virtualServer.getDefaultWebModule()); String aliases = ""; if (virtualServer.getAliasName() != null) { StringBuilder aliasBuilder = new StringBuilder(); for (String alias : virtualServer.getAliasName()) { aliasBuilder.append(", \"").append(alias).append("\""); } aliases = aliasBuilder.toString(); aliases = aliases.replaceFirst(", ", ""); if (!aliases.isEmpty()) { aliases = ", alias=[" + aliases + "]"; } } resultScript.append(builder.asString()).append(aliases).append(")"); return resultScript.toString(); }
/** * Creates CliCommandAction for adding a Virtual-Server * * @param server Virtual-Server * @return created CliCommandAction for adding the Virtual-Server * @throws CliScriptException if required attributes for a creation of the CLI command of the * Virtual-Server are missing or are empty (server-name) */ public static CliCommandAction createVirtualServerCliAction(VirtualServerBean server) throws CliScriptException { String errMsg = "in virtual-server (engine in AS5) must be set"; Utils.throwIfBlank(server.getVirtualServerName(), errMsg, "Server name"); ModelNode serverCmd = new ModelNode(); serverCmd.get(ClientConstants.OP).set(ClientConstants.ADD); serverCmd.get(ClientConstants.OP_ADDR).add("subsystem", "web"); serverCmd.get(ClientConstants.OP_ADDR).add("virtual-server", server.getVirtualServerName()); if (server.getAliasName() != null) { ModelNode aliasesNode = new ModelNode(); for (String alias : server.getAliasName()) { ModelNode aliasNode = new ModelNode(); aliasNode.set(alias); aliasesNode.add(aliasNode); } serverCmd.get("alias").set(aliasesNode); } CliApiCommandBuilder builder = new CliApiCommandBuilder(serverCmd); builder.addProperty("enable-welcome-root", server.getEnableWelcomeRoot()); builder.addProperty("default-web-module", server.getDefaultWebModule()); return new CliCommandAction( ServerMigrator.class, createVirtualServerScript(server), builder.getCommand()); }