Пример #1
0
  public static String saveTopologyData(Customer cust, TopologyData3 td) {
    String text = null;
    try {
      boolean needRollback = true;
      Connection c =
          ManagementContainer.getInstance().getDBConnection(ManagementContainer.POOL_NAME);
      try {
        TopologyStats ts = saveTopologyData(cust, td, c);
        if (td.getRunType() != DirectoryData.TYPE_MANUAL_NOCOMMIT) {
          c.commit();
          needRollback = false;
        }

        switch (td.getRunType()) {
          case DirectoryData.TYPE_MANUAL_FORCED:
            text =
                s_topologySuccessMessageForced.format(
                    new Object[] {
                      ts.getAdminGroupCount(), ts.getRoutingGroupCount(),
                      ts.getServerCount(), ts.getStoreCount()
                    });
            break;
          case DirectoryData.TYPE_MANUAL_NOCOMMIT:
            text =
                s_topologySuccessMessageNoCommit.format(
                    new Object[] {
                      ts.getAdminGroupCount(), ts.getRoutingGroupCount(),
                      ts.getServerCount(), ts.getStoreCount()
                    });
            break;
          default:
            text =
                s_topologySuccessMessage.format(
                    new Object[] {
                      ts.getAdminGroupCount(), ts.getRoutingGroupCount(),
                      ts.getServerCount(), ts.getStoreCount()
                    });
        }

        return text;
      } finally {
        if (needRollback) {
          c.rollback();
        }
        ManagementContainer.getInstance().safeReturnDBConnection(c, ManagementContainer.POOL_NAME);
        // report info **after** connection is closed
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("saveTopologyData completed: " + text);
        }
      }
    } catch (Exception e) {
      s_logger.error("Exception while saving the topology data.", e);
      return "An error occurred while saving the topology data.";
    }
  }
Пример #2
0
  private static TopologyStats saveTopologyData(Customer cust, TopologyData3 td, Connection c)
      throws SQLException {
    normalizeTopolgyData(td);

    int sourceID = getSourceID(cust, td.getSourceName(), c);

    // first, create all the sites and build a map to determine the IDs for servers
    ExchSite3[] adminGroups = td.getAdminGroups();
    Map adminGroupIDs = saveSites(adminGroups, CustomerGroup.TYPE_ADMIN, sourceID, c);
    int adminCount = adminGroups.length;

    ExchSite3[] routingGroups = td.getRoutingGroups();
    Map routingGroupIDs = saveSites(routingGroups, CustomerGroup.TYPE_ROUTING, sourceID, c);
    int routingCount = routingGroups.length;

    // next, create all the servers
    Map serverIDs = saveServers(td, sourceID, adminGroupIDs, routingGroupIDs, c);
    int serverCount = serverIDs.size();

    // create all the stores
    Map storeIDs = saveStores(td, sourceID, td.getAdminGroups(), serverIDs, c);
    int storeCount = storeIDs.size();

    // finally, do any necessary deletes
    Set groupIDs = new HashSet((adminGroupIDs.size() + routingGroupIDs.size()) * 2 + 1);
    groupIDs.addAll(adminGroupIDs.values());
    groupIDs.addAll(routingGroupIDs.values());
    deleteTopologyData(c, sourceID, groupIDs, serverIDs.values(), storeIDs.values());

    TopologyStats ts = new TopologyStats();
    ts.setAdminGroupCount(adminCount);
    ts.setRoutingGroupCount(routingCount);
    ts.setServerCount(serverCount);
    ts.setStoreCount(storeCount);
    return ts;
  }
Пример #3
0
  private static Map saveServers(
      TopologyData3 td, int sourceID, Map adminGroupIDs, Map routingGroupIDs, Connection c)
      throws SQLException {
    PreparedStatement insert = null;
    PreparedStatement update = null;
    try {
      insert =
          c.prepareStatement(
              "insert into dat_customer_servers (server_id, source_id, admin_group_id, routing_group_id, internal_name, display_name, sink_capable, sink_enabled, server_role, server_version, cloud_service_id) "
                  + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
      update =
          c.prepareStatement(
              "update dat_customer_servers "
                  + "set source_id = ?, admin_group_id = ?, routing_group_id = ?, internal_name = ?, "
                  + "    display_name = ?, sink_capable = ?, server_role = ?, server_version = ?, is_deleted = false, purge_time = NULL, cloud_service_id = ? "
                  + "where server_id = ?");

      Map serverIDs = new HashMap(adminGroupIDs.size() * 8 + 1);
      ExchSite3[] adminGroups = td.getAdminGroups();
      ExchSite3[] routingGroups = td.getRoutingGroups();
      for (int i = 0; i < adminGroups.length; i++) {
        ExchSite3 adminGroup = adminGroups[i];
        int adminGroupID = ((Number) adminGroupIDs.get(adminGroup.getInternalName())).intValue();
        ExchServer3[] servers = adminGroup.getServers();
        for (int j = 0; j < servers.length; j++) {
          ExchServer3 server = servers[j];

          int serverID = queryLookupServerId(sourceID, server.getInternalName(), c);
          int routingGroupID =
              findRoutingGroupID(server.getInternalName(), routingGroups, routingGroupIDs);

          // for non-sinkable servers, attempt to parse cloud service from version field
          CloudService cloudService = CloudService.NONE;
          if (!server.isSinkCapable()) {
            Matcher matcher = SERVER_VERSION_PATTERN.matcher(server.getServerVersion());

            if (matcher.matches()) {
              cloudService = CloudService.valueOfCaseInsensitive(matcher.group(1), cloudService);
            }
          }

          if (serverID == 0) {
            // if we couldn't find an existing serverID, grab the next one from the sequence
            serverID = getNextFromSequence("seq_server_id", c);
            serverIDs.put(server.getInternalName(), serverID);
            insert.setInt(1, serverID);
            insert.setInt(2, sourceID);
            insert.setInt(3, adminGroupID);
            insert.setInt(4, routingGroupID);
            insert.setString(
                5,
                DirectoryUtils.truncateString(
                    server.getInternalName(), DB_SERVER_INTERNALNAME_LENGTH));
            insert.setString(
                6,
                DirectoryUtils.truncateString(
                    server.getDisplayName(), DB_SERVER_DISPLAYNAME_LENGTH));
            insert.setInt(7, server.isSinkCapable() ? 1 : 0);
            insert.setInt(
                8,
                cloudService.getId() <= CloudService.ONPREMISES.getId()
                    ? 1
                    : 0); // by default, all non-cloud servers are sink-enabled (so if they become
                          // e2k servers, they're enabled)
            insert.setInt(9, server.getServerRole());
            insert.setString(
                10,
                DirectoryUtils.truncateString(server.getServerVersion(), DB_SERVER_VERSION_LENGTH));
            insert.setInt(11, cloudService.getId());
            insert.executeUpdate();
          } else {
            // if there is an existing serverID, update it (preserve value of sink_enabled)
            serverIDs.put(server.getInternalName(), serverID);
            update.setInt(1, sourceID);
            update.setInt(2, adminGroupID);
            update.setInt(3, routingGroupID);
            update.setString(
                4,
                DirectoryUtils.truncateString(
                    server.getInternalName(), DB_SERVER_INTERNALNAME_LENGTH));
            update.setString(
                5,
                DirectoryUtils.truncateString(
                    server.getDisplayName(), DB_SERVER_DISPLAYNAME_LENGTH));
            update.setInt(6, server.isSinkCapable() ? 1 : 0);
            update.setInt(7, server.getServerRole());
            update.setString(
                8,
                DirectoryUtils.truncateString(server.getServerVersion(), DB_SERVER_VERSION_LENGTH));
            update.setInt(9, cloudService.getId());
            update.setInt(10, serverID);
            update.executeUpdate();
          }
        }
      }
      return serverIDs;
    } finally {
      if (update != null) {
        update.close();
      }
      if (insert != null) {
        insert.close();
      }
    }
  }
Пример #4
0
 private static void normalizeTopolgyData(TopologyData3 td) {
   normalizeTopolgyData(td.getAdminGroups());
   normalizeTopolgyData(td.getRoutingGroups());
 }