// Unauthorizing public APIs for non-control nodes.
 @Override
 protected AbstractRequestWrapper authenticate(final ServletRequest servletRequest) {
   HttpServletRequest req = (HttpServletRequest) servletRequest;
   _log.debug("Is node control node? " + _coordinatorclientext.isControlNode());
   if (!_coordinatorclientext.isControlNode()) {
     _log.info("URI is not allowed: " + req.getRequestURI());
     throw APIException.unauthorized.methodNotAllowedOnThisNode();
   }
   return null;
 }
  /**
   * Generates configuration file with name taken from variable CONFIG_FILE_NAME Returns the created
   * file name.
   */
  protected String generateConfigFile()
      throws JAXBException, LocalRepositoryException, IOException {
    ZipOutputStream zos = null;
    try {
      PropertyInfoExt properties =
          new PropertyInfoExt(coordinator.getPropertyInfo().getProperties());
      zos = new ZipOutputStream(new FileOutputStream(CONFIG_FILE_PATH));
      ZipEntry ze = new ZipEntry(CONFIG_FILE_NAME + getFileExtension());
      zos.putNextEntry(ze);

      if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
        (new ObjectMapper()).writeValue(zos, properties); // gson should not be used any more
      } else {
        JAXBContext jaxbContext = JAXBContext.newInstance(PropertyInfo.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(properties, zos);
      }
      zos.flush();
    } finally {
      if (zos != null) {
        zos.close();
      }
    }

    return CONFIG_FILE_PATH;
  }
 public SendEvent(
     ServiceImpl service,
     LogSvcPropertiesLoader logSvcPropertiesLoader,
     MediaType mediaType,
     LicenseInfoExt licenseInfo,
     CoordinatorClientExt coordinator) {
   URI endpointUri = coordinator.getNodeEndpoint(service.getEndpoint().getHost());
   _networkIpAddress =
       (endpointUri != null)
           ? coordinator.getIPAddrFromUri(endpointUri)
           : service.getEndpoint().getHost();
   _log.info("_networkIpAddress: {}", _networkIpAddress);
   _identifierManager = IdentifierManager.getInstance();
   this.logSvcPropertiesLoader = logSvcPropertiesLoader;
   this.mediaType = mediaType;
   this.licenseInfo = licenseInfo;
   this.coordinator = coordinator;
 }
  @Override
  public void start() throws Exception {
    if (_app != null) {

      initThreadUncaughtExceptionHandler();

      initServer();
      initSysClientFactory();
      _server.start();

      // only data node needs to poll the cluster's address change
      if (!_coordinator.isControlNode()) {
        _clusterPoller.start();
      }

      startNewVersionCheck();
      startUpgradeManager();
      startSecretsManager();
      startPropertyManager();
      startVdcManager();
      startIpReconfigManager();

      // config cassandra as client mode to avoid load yaml file
      Config.setClientMode(true);

      DrUtil drUtil = _coordinator.getDrUtil();
      if (drUtil.isActiveSite()) {
        _recoveryMgr.init();
        startSystemAudit(_dbClient);
      }
      _svcBeacon.start();

      if (drUtil.isActiveSite()) {
        startNetworkMonitor();
      }
    } else {
      throw new Exception("No app found.");
    }
  }
  /**
   * Build the Device object using the controller license information.
   *
   * @param feature
   * @param device
   * @throws LocalRepositoryException
   */
  private void buildDevice(LicenseInfoExt licenseInfo, Device device)
      throws LocalRepositoryException {

    if (licenseInfo != null) {
      LocalRepository localRepository = LocalRepository.getInstance();
      // this is in the format of node1, node2, etc. We need to get the integer portion.
      String nodeId = _coordinator.getPropertyInfo().getProperties().get("node_id");
      String node;
      if (nodeId != null) {
        node = nodeId.substring(4);
      } else {
        node = CallHomeConstants.STANDALONE;
      }
      device.setSerialNumber(licenseInfo.getProductId() + "-" + node);
      device.setModelName(getBaseModelId(licenseInfo.getModelId()) + MODEL_NAME_SUFFIX);
      device.setIpAddress(_networkIpAddress);
    }
  }
 private void startSystemAudit(DbClient dbclient) {
   SystemAudit sysAudit = new SystemAudit(dbclient, _coordinator.getCoordinatorClient());
   Thread t = new Thread(sysAudit);
   t.start();
 }
 private void stopNewVersionCheck() {
   if (_coordinator.isControlNode()) {
     RemoteRepository.stopRemoteRepositoryCacheUpdate();
   }
 }
 private void startNewVersionCheck() {
   if (_coordinator.isControlNode()) {
     RemoteRepository.setCoordinator(_coordinator);
     RemoteRepository.startRemoteRepositoryCacheUpdate();
   }
 }