Exemple #1
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;
  }
Exemple #2
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.";
    }
  }