Пример #1
0
  /**
   * Creates a socket-binding if it doesn't already exists.
   *
   * @param port port of the connector, which will be converted to socket-binding
   * @param name name of the protocol which is used by connector (ajp/http/https)
   * @return name of the socket-binding so it cant be referenced in connector
   * @throws NodeGenerationException if createDefaultSocket fails to unmarshall socket-bindings
   */
  private static String createSocketBinding(
      String port, String name, ServerMigratorResource resource) throws NodeGenerationException {
    // TODO: Refactor and change the logic MIGR-71
    for (SocketBindingBean sb : resource.getSocketTemp()) {
      if (sb.getSocketPort().equals(port)) {
        return sb.getSocketName();
      }
      if (sb.getSocketName().equals(name)) {
        name = "createdSocket";
      }
    }

    SocketBindingBean socketBinding = new SocketBindingBean();

    for (SocketBindingBean sb : resource.getSocketBindings()) {
      if (sb.getSocketPort().equals(port)) {
        return sb.getSocketName();
      }
    }

    for (SocketBindingBean sb : resource.getSocketBindings()) {
      if (sb.getSocketName().equals(name)) {
        name = name.concat(resource.getRandomSocket().toString());
      }
    }

    socketBinding.setSocketName(name);
    socketBinding.setSocketPort(port);

    resource.getSocketBindings().add(socketBinding);

    return name;
  }
Пример #2
0
  /**
   * Creates CopyFileAction for keystores files from Connectors
   *
   * @param resource helping class containing all resources for ServerMigrator
   * @param fName name of the keystore file to be copied into AS7
   * @return null if the file is already set for copying or the file cannot be found in the AS5
   *     structure else created CopyFileAction
   */
  private CopyFileAction createCopyActionForKeyFile(ServerMigratorResource resource, String fName) {
    // TODO:
    final String property = "${jboss.server.home.dir}";

    // TODO: MIGR-54 The paths in AS 5 config relate to some base dir. Find out which and use that,
    // instead of searching.
    //       Then, create the actions directly in the code creating this "files to copy" collection.
    File as5profileDir = getGlobalConfig().getAS5Config().getProfileDir();
    File src;
    try {
      src = Utils.searchForFile(fName, as5profileDir).iterator().next();
    } catch (CopyException ex) {
      // throw new ActionException("Failed copying a security file: " + ex.getMessage(), ex);
      // Some files referenced in security may not exist. (?)
      log.warn("Couldn't find file referenced in AS 5 server config: " + fName);
      return null;
    }

    if (!resource.getKeystores().add(src)) return null;

    File target =
        Utils.createPath(getGlobalConfig().getAS7Config().getConfigDir(), "keys", src.getName());
    CopyFileAction action =
        new CopyFileAction(this.getClass(), src, target, CopyFileAction.IfExists.SKIP);
    return action;
  }
Пример #3
0
  @Override
  public void createActions(MigrationContext ctx) throws MigrationException {
    ServerMigratorResource resource = new ServerMigratorResource();

    try {
      createDefaultSockets(ctx, resource);
    } catch (LoadMigrationException e) {
      throw new MigrationException("Migration of web server failed: " + e.getMessage(), e);
    }

    for (IConfigFragment fragment :
        ctx.getMigrationData().get(ServerMigrator.class).getConfigFragments()) {
      String what = null;
      try {
        if (fragment instanceof ConnectorAS5Bean) {
          what = "connector";
          ctx.getActions()
              .addAll(
                  createConnectorCliAction(
                      migrateConnector((ConnectorAS5Bean) fragment, resource, ctx)));
        } else if (fragment instanceof EngineBean) {
          what = "Engine (virtual-server)";
          ctx.getActions().add(createVirtualServerCliAction(migrateEngine((EngineBean) fragment)));
        } else
          throw new MigrationException(
              "Config fragment unrecognized by "
                  + this.getClass().getSimpleName()
                  + ": "
                  + fragment);
      } catch (CliScriptException | NodeGenerationException e) {
        throw new MigrationException("Migration of the " + what + " failed: " + e.getMessage(), e);
      }
    }

    for (SocketBindingBean sb : resource.getSocketBindings()) {
      try {
        ctx.getActions().add(createSocketBindingCliAction(sb));
      } catch (CliScriptException e) {
        throw new MigrationException(
            "Creation of the new socket-binding failed: " + e.getMessage(), e);
      }
    }
  }
Пример #4
0
  /**
   * Loads socket-bindings, which are already defined in fresh standalone files.
   *
   * @param ctx migration context
   * @throws LoadMigrationException if unmarshalling socket-bindings from standalone file fails
   */
  private void createDefaultSockets(MigrationContext ctx, ServerMigratorResource resource)
      throws LoadMigrationException {
    try {
      Unmarshaller unmarshaller =
          JAXBContext.newInstance(SocketBindingBean.class).createUnmarshaller();

      // TODO:  Read over Management API. MIGR-71
      NodeList bindings = ctx.getAS7ConfigXmlDoc().getElementsByTagName("socket-binding");
      for (int i = 0; i < bindings.getLength(); i++) {
        if (!(bindings.item(i) instanceof Element)) {
          continue;
        }
        SocketBindingBean socketBinding =
            (SocketBindingBean) unmarshaller.unmarshal(bindings.item(i));
        if ((socketBinding.getSocketName() != null) || (socketBinding.getSocketPort() != null)) {
          resource.getSocketTemp().add(socketBinding);
        }
      }
    } catch (JAXBException e) {
      throw new LoadMigrationException(
          "Parsing of socket-bindings in standalone file failed: " + e.getMessage(), e);
    }
  }