First part of onap rename
[appc.git] / appc-oam / appc-oam-bundle / src / main / java / org / openecomp / appc / oam / util / ConfigurationHelper.java
index c465b9b..3c5629f 100644 (file)
  * ============LICENSE_END=========================================================
  */
 
-package org.openecomp.appc.oam.util;
+package org.onap.appc.oam.util;
 
 import com.att.eelf.configuration.EELFLogger;
 import org.apache.commons.lang3.ArrayUtils;
-import org.openecomp.appc.Constants;
-import org.openecomp.appc.configuration.Configuration;
-import org.openecomp.appc.configuration.ConfigurationFactory;
+import org.onap.appc.Constants;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+
+import java.util.concurrent.TimeUnit;
 
 /**
  * Utility class provides general configuration helps
@@ -36,6 +38,9 @@ import org.openecomp.appc.configuration.ConfigurationFactory;
 public class ConfigurationHelper {
     final static String PROP_KEY_APPC_NAME = Constants.PROPERTY_APPLICATION_NAME;
     final static String PROP_KEY_METRIC_STATE = "metric.enabled";
+    private final String OAM_OPERATION_TIMEOUT_SECOND = "appc.OAM.api.timeout";
+    /** Default operation timeout set to 1 minute */
+    private final int DEFAULT_OAM_OPERATION_TIMEOUT = 60;
 
     private final EELFLogger logger;
     private Configuration configuration = ConfigurationFactory.getConfiguration();
@@ -57,7 +62,7 @@ public class ConfigurationHelper {
     }
 
     /**
-     * Read property value of a specified proeprty key
+     * Read property value of a specified property key
      *
      * @param propertyKey string of the property key
      * @return String[] of the property values associated with the propertyKey
@@ -77,4 +82,25 @@ public class ConfigurationHelper {
         }
         return new String[]{propertyValue};
     }
+
+
+
+
+
+    /**
+     * This method returns timeout in milliseconds.  The source is chosen in the following order:
+     * The overrideTimeoutSeconds argument
+     * or {@link #OAM_OPERATION_TIMEOUT_SECOND} found in the configuration file
+     * or the {@link #DEFAULT_OAM_OPERATION_TIMEOUT}
+     * @param overrideTimeoutSeconds  or null to us the other sources
+     * @return timeout in milliseconds
+     */
+    public long getOAMOperationTimeoutValue(Integer overrideTimeoutSeconds) {
+        return TimeUnit.SECONDS.toMillis(
+                overrideTimeoutSeconds == null ?
+            getConfig().getIntegerProperty(OAM_OPERATION_TIMEOUT_SECOND, DEFAULT_OAM_OPERATION_TIMEOUT)
+            :
+            overrideTimeoutSeconds
+        );
+    }
 }