Beispiel #1
0
  private static Map saveSites(ExchSite3[] sites, int siteType, int sourceID, Connection c)
      throws SQLException {
    PreparedStatement insert = null;
    PreparedStatement delete = null;
    try {
      insert =
          c.prepareStatement(
              "insert into dat_customer_sites (site_id, site_type, source_id, internal_name, display_name) "
                  + "values (?, ?, ?, ?, ?)");
      delete = c.prepareStatement("delete from dat_customer_sites where site_id = ?");

      Map siteIDs = new HashMap(sites.length * 2 + 1);
      for (int i = 0; i < sites.length; i++) {
        ExchSite3 site = sites[i];

        int siteID = queryLookupSiteId(sourceID, site.getInternalName(), siteType, c);

        if (siteID == 0) {
          // if we couldn't find an existing siteID, grab the next one from the sequence
          siteID = getNextFromSequence("seq_site_id", c);
        } else {
          // if there is an existing siteID, delete it so we can insert the changes
          delete.setInt(1, siteID);
          int deleted = delete.executeUpdate();
          if (deleted != 1) {
            throw new SQLException("Delete for siteID " + siteID + " returned " + deleted);
          }
        }

        siteIDs.put(site.getInternalName(), siteID);
        insert.setInt(1, siteID);
        insert.setInt(2, siteType);
        insert.setInt(3, sourceID);
        insert.setString(
            4, DirectoryUtils.truncateString(site.getInternalName(), DB_SITE_INTERNALNAME_LENGTH));
        insert.setString(
            5, DirectoryUtils.truncateString(site.getDisplayName(), DB_SITE_DISPLAYNAME_LENGTH));
        insert.executeUpdate();
      }
      return siteIDs;
    } finally {
      if (delete != null) {
        delete.close();
      }
      if (insert != null) {
        insert.close();
      }
    }
  }
Beispiel #2
0
 private static int findRoutingGroupID(
     String svrInternalName, ExchSite3[] routingGroups, Map routingGroupIDs) {
   for (int i = 0; i < routingGroups.length; i++) {
     ExchSite3 rg = routingGroups[i];
     ExchServer3[] servers = rg.getServers();
     for (int j = 0; j < servers.length; j++) {
       ExchServer3 svr = servers[j];
       if (svrInternalName.equals(svr.getInternalName())) {
         return ((Number) routingGroupIDs.get(rg.getInternalName())).intValue();
       }
     }
   }
   s_logger.error("Couldn't find routing group for server '" + svrInternalName + "'.");
   return -1;
 }
Beispiel #3
0
 private static void normalizeTopolgyData(ExchSite3[] groups) {
   for (int i = 0; i < groups.length; i++) {
     ExchSite3 site = groups[i];
     site.setInternalName(DirectoryUtils.escapeCommas(site.getInternalName()));
     ExchServer3[] servers = site.getServers();
     for (int j = 0; j < servers.length; j++) {
       ExchServer3 server = servers[j];
       server.setInternalName(DirectoryUtils.escapeCommas(server.getInternalName()));
       ExchStore2[] stores = server.getStores();
       for (int k = 0; k < stores.length; k++) {
         ExchStore2 store = stores[k];
         store.setInternalName(DirectoryUtils.escapeCommas(store.getInternalName()));
       }
     }
   }
 }
Beispiel #4
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();
      }
    }
  }
Beispiel #5
0
  private static Map saveStores(
      TopologyData3 td, int sourceID, ExchSite3[] sites, Map serverIDs, Connection c)
      throws SQLException {
    PreparedStatement insert = null;
    PreparedStatement delete = null;
    try {
      insert =
          c.prepareStatement(
              "insert into dat_customer_stores (store_id, source_id, server_id, internal_name, display_name) "
                  + "values (?, ?, ?, ?, ?)");
      delete = c.prepareStatement("delete from dat_customer_stores where store_id = ?");

      Map storeIDs = new HashMap(101);

      for (int i = 0; i < sites.length; i++) {
        ExchSite3 site = sites[i];
        ExchServer3[] servers = site.getServers();
        for (int j = 0; j < servers.length; j++) {
          ExchServer3 server = servers[j];
          int serverID = ((Number) serverIDs.get(server.getInternalName())).intValue();
          ExchStore2[] stores = server.getStores();
          for (int k = 0; k < stores.length; k++) {
            ExchStore2 store = stores[k];

            int storeId = queryLookupStoreId(sourceID, store.getInternalName(), c);

            if (storeId == 0) {
              // if we couldn't find an existing storeID, grab the next one from the sequence
              storeId = getNextFromSequence("seq_store_id", c);
            } else {
              // if there is an existing storeID, delete it so we can insert the changes
              delete.setInt(1, storeId);
              int deleted = delete.executeUpdate();
              if (deleted != 1) {
                throw new SQLException("Delete for store " + storeId + " returned " + deleted);
              }
            }

            storeIDs.put(store.getInternalName(), storeId);
            insert.setInt(1, storeId);
            insert.setInt(2, sourceID);
            insert.setInt(3, serverID);
            insert.setString(
                4,
                DirectoryUtils.truncateString(
                    store.getInternalName(), DB_STORE_INTERNALNAME_LENGTH));
            insert.setString(
                5,
                DirectoryUtils.truncateString(store.getDisplayName(), DB_STORE_DISPLAYNAME_LENGTH));
            insert.executeUpdate();
          }
        }
      }
      return storeIDs;
    } finally {
      if (delete != null) {
        delete.close();
      }
      if (insert != null) {
        insert.close();
      }
    }
  }