@Test
 public void archiveDefinition() {
   AdminContextImpl impl = new AdminContextImpl();
   BackupManager mgr = createMock(BackupManager.class);
   replay(mgr);
   BackupSettings settings = new BackupSettings();
   settings.setModelFilesContext(TestHelper.getModelFilesContext());
   Location primary = new Location("one.example.org", "1.1.1.1");
   primary.setPrimary(true);
   ArchiveDefinition def = impl.getArchiveDefinitions(mgr, primary, settings).iterator().next();
   String base = "$(sipx.SIPX_BINDIR)/sipxconfig-archive --restore %s --ipaddress $(sipx.bind_ip)";
   String baseBackup = "$(sipx.SIPX_BINDIR)/sipxconfig-archive --backup %s";
   assertEquals(base, def.getRestoreCommand());
   assertEquals(baseBackup, def.getBackupCommand());
   settings.setSettingTypedValue("backup/device", Boolean.FALSE);
   settings.setSettingTypedValue("restore/keepDomain", Boolean.TRUE);
   settings.setSettingTypedValue("restore/keepFqdn", Boolean.TRUE);
   settings.setSettingTypedValue("restore/decodePins", Boolean.TRUE);
   settings.setSettingTypedValue("restore/decodePinMaxLen", (Integer) 5);
   settings.setSettingTypedValue("restore/resetPin", "zzz");
   settings.setSettingTypedValue("restore/resetPassword", "yyy");
   def = impl.getArchiveDefinitions(mgr, primary, settings).iterator().next();
   String options =
       " --domain $(sipx.domain) --fqdn $(sipx.host).$(sipx.net_domain) --crack-pin zzz --crack-passwd yyy --crack-pin-len 5";
   String backupOptions = " --no-device-files";
   assertEquals(base + options, def.getRestoreCommand());
   assertEquals(baseBackup + backupOptions, def.getBackupCommand());
   verify(mgr);
 }
 @Override
 public Collection<Address> getAvailableAddresses(
     AddressManager manager, AddressType type, Location requester) {
   if (!type.equalsAnyOf(ADDRESS_ID)) {
     return null;
   }
   Collection<Location> locations =
       manager.getFeatureManager().getLocationsForEnabledFeature(FEATURE_ID);
   Collection<Address> addresses = new ArrayList<Address>(locations.size());
   for (Location location : locations) {
     addresses.add(new Address(ADDRESS_ID, location.getAddress(), MongoSettings.SERVER_PORT));
   }
   return addresses;
 }
Exemple #3
0
  @Override
  public Address getSingleAddress(
      AddressType t, Collection<Address> addresses, Location whoIsAsking) {
    if (addresses == null || addresses.size() == 0) {
      return null;
    }

    for (DnsProvider p : getProviders()) {
      Address rewrite = p.getAddress(this, t, addresses, whoIsAsking);
      if (rewrite != null) {
        return rewrite;
      }
    }

    Iterator<Address> i = addresses.iterator();
    Address first = i.next();
    if (addresses.size() == 1 || whoIsAsking == null) {
      return first;
    }

    // return the address local to who is asking if available
    Address a = first;
    while (a != null) {
      if (a.getAddress().equals(whoIsAsking.getAddress())) {
        return a;
      }
      a = (i.hasNext() ? i.next() : null);
    }

    // first is as good as any other
    return first;
  }
 @Override
 public Collection<LocationFeature> getAvailableLocationFeatures(Location l) {
   if (l.isPrimary()) {
     return Collections.singleton(ARBITER_FEATURE);
   }
   return Arrays.asList(FEATURE_ID, ARBITER_FEATURE);
 }
Exemple #5
0
 @Override
 public Collection<Address> getAvailableAddresses(
     AddressManager manager, AddressType type, Location requester) {
   if (!type.equals(DNS_ADDRESS)) {
     return null;
   }
   List<Location> locations = manager.getFeatureManager().getLocationsForEnabledFeature(FEATURE);
   return Location.toAddresses(DNS_ADDRESS, locations);
 }
 @Override
 public Collection<ProcessDefinition> getProcessDefinitions(
     SnmpManager manager, Location location) {
   Collection<ProcessDefinition> procs = new ArrayList<ProcessDefinition>(2);
   if (manager.getFeatureManager().isFeatureEnabled(FEATURE_ID, location)
       || location.isPrimary()) {
     procs.add(new ProcessDefinition("mongod", ".*/mongod.*-f.*/mongod.conf"));
   }
   if (manager.getFeatureManager().isFeatureEnabled(ARBITER_FEATURE, location)) {
     procs.add(new ProcessDefinition("mongoArbiter", ".*/mongod.*-f.*/mongod-arbiter.conf"));
   }
   return procs;
 }
Exemple #7
0
  @Override
  public void replicate(ConfigManager manager, ConfigRequest request) throws IOException {
    if (!request.applies(
        DialPlanContext.FEATURE,
        Ivr.FEATURE,
        Mwi.FEATURE,
        RestServer.FEATURE,
        ImBot.FEATURE,
        FreeswitchFeature.FEATURE,
        AdminContext.FEATURE,
        ApacheManager.FEATURE,
        ImManager.FEATURE)) {
      return;
    }
    Set<Location> locations = request.locations(manager);
    FeatureManager featureManager = manager.getFeatureManager();
    Address adminApi = manager.getAddressManager().getSingleAddress(AdminContext.HTTP_ADDRESS_AUTH);
    Address apacheApi = manager.getAddressManager().getSingleAddress(ApacheManager.HTTPS_ADDRESS);
    Address restApi = manager.getAddressManager().getSingleAddress(RestServer.HTTP_API);
    Address imApi = manager.getAddressManager().getSingleAddress(ImManager.XMLRPC_ADDRESS);
    Address imbotApi = manager.getAddressManager().getSingleAddress(ImBot.REST_API);
    Address fsEvent = manager.getAddressManager().getSingleAddress(FreeswitchFeature.EVENT_ADDRESS);
    IvrSettings settings = m_ivr.getSettings();
    Domain domain = manager.getDomainManager().getDomain();
    List<Location> mwiLocations =
        manager.getFeatureManager().getLocationsForEnabledFeature(Mwi.FEATURE);
    int mwiPort = m_mwi.getSettings().getHttpApiPort();
    for (Location location : locations) {
      File dir = manager.getLocationDataDirectory(location);
      boolean enabled = featureManager.isFeatureEnabled(Ivr.FEATURE, location);

      ConfigUtils.enableCfengineClass(dir, "sipxivr.cfdat", enabled, "sipxivr");
      if (!enabled) {
        continue;
      }
      File f = new File(dir, "sipxivr.properties.part");
      Writer wtr = new FileWriter(f);
      Set<String> mwiAddresses = new LinkedHashSet<String>();
      mwiAddresses.add(location.getAddress());
      for (Location mwiLocation : mwiLocations) {
        mwiAddresses.add(mwiLocation.getAddress());
      }
      try {
        write(
            wtr,
            settings,
            domain,
            location,
            StringUtils.join(mwiAddresses, ","),
            mwiPort,
            restApi,
            adminApi,
            apacheApi,
            imApi,
            imbotApi,
            fsEvent);
      } finally {
        IOUtils.closeQuietly(wtr);
      }
    }
  }