@Override
 public boolean validateStorageProviderConnection(
     String ipAddress, Integer portNumber, String interfaceType) {
   // Making a direct call to get connection status.
   Controller controller = lookupDeviceController();
   BlockController blkcontroller = (BlockController) controller;
   return blkcontroller.validateStorageProviderConnection(ipAddress, portNumber, interfaceType);
 }
 private boolean isOldConnectionAlive(String ipAddress, Integer portNumber, String interfaceType) {
   log.info("Validating {} storage provider connection at {}.", interfaceType, ipAddress);
   if (StorageProvider.InterfaceType.vplex.name().equals(interfaceType)) {
     VPlexController controller =
         getController(VPlexController.class, DiscoveredDataObject.Type.vplex.toString());
     return controller.validateStorageProviderConnection(ipAddress, portNumber);
   } else {
     BlockController controller = getController(BlockController.class, "vnxblock");
     return controller.validateStorageProviderConnection(ipAddress, portNumber, interfaceType);
   }
 }
 @Override
 public Integer checkSyncProgress(URI storage, URI source, URI target, String opId) {
   try {
     StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
     Controller controller = lookupDeviceController(storageSystem);
     BlockController blkcontroller = (BlockController) controller;
     return blkcontroller.checkSyncProgress(storage, source, target, opId);
   } catch (RetryableDatabaseException e) {
     if (e.getServiceCode() == ServiceCode.DBSVC_CONNECTION_ERROR) {
       // netflix curator ConnectionException is not serializable
       // and thus should not be sent back to rmi client.
       _log.error("Failed to queue task due to dbsvc disconnected. Error: {}", e.getMessage());
       _log.error(e.getMessage(), e);
       throw DatabaseException.retryables.connectionFailed();
     }
     throw e;
   }
 }
 @Override
 public void activateFullCopy(URI storage, List<URI> fullCopy, String opId) {
   try {
     // Direct RMI call to expedite this call without any potential distribute-Q delay
     StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
     Controller controller = lookupDeviceController(storageSystem);
     BlockController blkcontroller = (BlockController) controller;
     blkcontroller.activateFullCopy(storage, fullCopy, opId);
   } catch (RetryableDatabaseException e) {
     if (e.getServiceCode() == ServiceCode.DBSVC_CONNECTION_ERROR) {
       // netflix curator ConnectionException is not serializable
       // and thus should not be sent back to rmi client.
       _log.error("Failed to queue task due to dbsvc disconnected. Error: {}", e.getMessage());
       _log.error(e.getMessage(), e);
       throw DatabaseException.retryables.connectionFailed();
     }
     throw e;
   }
 }
  @POST
  @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
  @CheckPermission(roles = {Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN})
  public TaskResourceRep registerStorageProvider(StorageProviderCreateParam param)
      throws ControllerException {
    ArgValidator.checkFieldNotEmpty(param.getName(), "name");
    checkForDuplicateName(param.getName(), StorageProvider.class);

    ArgValidator.checkFieldNotEmpty(param.getIpAddress(), "ip_address");
    ArgValidator.checkFieldNotNull(param.getPortNumber(), "port_number");
    ArgValidator.checkFieldNotEmpty(param.getUserName(), "user_name");
    ArgValidator.checkFieldNotEmpty(param.getPassword(), "password");
    ArgValidator.checkFieldRange(param.getPortNumber(), 1, 65535, "port_number");
    ArgValidator.checkFieldValueFromEnum(
        param.getInterfaceType(), "interface_type", StorageProvider.InterfaceType.class);
    String providerKey = param.getIpAddress() + "-" + param.getPortNumber();
    List<StorageProvider> providers =
        CustomQueryUtility.getActiveStorageProvidersByProviderId(_dbClient, providerKey);
    if (providers != null && !providers.isEmpty()) {
      throw APIException.badRequests.invalidParameterStorageProviderAlreadyRegistered(providerKey);
    }

    // Set the SSL parameter
    Boolean useSSL = param.getUseSSL();
    if (useSSL == null) {
      useSSL = StorageProviderCreateParam.USE_SSL_DEFAULT;
    }

    StorageProvider provider = new StorageProvider();
    provider.setId(URIUtil.createId(StorageProvider.class));
    provider.setLabel(param.getName());
    provider.setIPAddress(param.getIpAddress());
    provider.setPortNumber(param.getPortNumber());
    provider.setUserName(param.getUserName());
    provider.setPassword(param.getPassword());
    provider.setUseSSL(useSSL);
    provider.setInterfaceType(param.getInterfaceType());
    provider.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
    provider.setConnectionStatus(ConnectionStatus.INITIALIZING.name());
    provider.setSecondaryUsername(param.getSecondaryUsername());
    provider.setSecondaryPassword(param.getSecondaryPassword());
    provider.setElementManagerURL(param.getElementManagerURL());
    if (param.getSioCLI() != null) {
      // TODO: Validate the input?
      provider.addKey(StorageProvider.GlobalKeys.SIO_CLI.name(), param.getSioCLI());
    }

    if (StorageProvider.InterfaceType.ibmxiv.name().equalsIgnoreCase(provider.getInterfaceType())) {
      provider.setManufacturer("IBM");
    }

    _dbClient.createObject(provider);

    auditOp(
        OperationTypeEnum.REGISTER_STORAGEPROVIDER,
        true,
        null,
        provider.getLabel(),
        provider.getId().toString(),
        provider.getIPAddress(),
        provider.getPortNumber(),
        provider.getUserName(),
        provider.getInterfaceType());

    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
    String taskId = UUID.randomUUID().toString();
    tasks.add(new AsyncTask(StorageProvider.class, provider.getId(), taskId));

    BlockController controller = getController(BlockController.class, provider.getInterfaceType());
    log.debug("controller.getClass().getName() :{}", controller.getClass().getName());
    log.debug("controller.getClass().getSimpleName() :{}", controller.getClass().getSimpleName());
    /**
     * Creates MonitoringJob token for vnxblock/vmax, hds, cinder and IBM XIV device on zooKeeper
     * queue
     */
    // TODO : If all interface types have monitoring impl class added (scaleIO is missing),
    // this check can be removed.
    String interfaceType = provider.getInterfaceType();
    if (StorageProvider.InterfaceType.hicommand.name().equalsIgnoreCase(interfaceType)
        || StorageProvider.InterfaceType.smis.name().equalsIgnoreCase(interfaceType)
        || StorageProvider.InterfaceType.cinder.name().equalsIgnoreCase(interfaceType)
        || StorageProvider.InterfaceType.ibmxiv.name().equalsIgnoreCase(interfaceType)) {
      controller.startMonitoring(
          new AsyncTask(StorageProvider.class, provider.getId(), taskId),
          getSystemTypeByInterface(interfaceType));
    }

    DiscoveredObjectTaskScheduler scheduler =
        new DiscoveredObjectTaskScheduler(_dbClient, new ScanJobExec(controller));
    TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
    return taskList.getTaskList().listIterator().next();
  }