Refactor cloud-utils project into Maven default structure
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/83fd8f60 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/83fd8f60 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/83fd8f60 Branch: refs/heads/deploy-from-snapshot Commit: 83fd8f60f3c503cf6fda7833b0f45c23a215f559 Parents: 3d27e9e Author: Miguel Ferreira <miguelferre...@me.com> Authored: Sun Aug 23 16:03:11 2015 +0200 Committer: Miguel Ferreira <miguelferre...@me.com> Committed: Tue Aug 25 14:50:33 2015 +0200 ---------------------------------------------------------------------- utils/certs/cloud.keystore | Bin 1316 -> 0 bytes utils/pom.xml | 44 +- utils/src/com/cloud/maint/Version.java | 77 - utils/src/com/cloud/utils/ActionDelegate.java | 24 - .../src/com/cloud/utils/AutoCloseableUtil.java | 36 - .../com/cloud/utils/CloudResourceBundle.java | 48 - .../com/cloud/utils/ConstantTimeComparator.java | 42 - utils/src/com/cloud/utils/DateUtil.java | 274 ---- utils/src/com/cloud/utils/EncryptionUtil.java | 73 - utils/src/com/cloud/utils/EnumUtils.java | 58 - utils/src/com/cloud/utils/ExecutionResult.java | 46 - utils/src/com/cloud/utils/FileUtil.java | 32 - utils/src/com/cloud/utils/HttpUtils.java | 114 -- utils/src/com/cloud/utils/IteratorUtil.java | 72 - utils/src/com/cloud/utils/Journal.java | 104 -- utils/src/com/cloud/utils/LogUtils.java | 45 - utils/src/com/cloud/utils/MethodCapturer.java | 113 -- utils/src/com/cloud/utils/NumbersUtil.java | 139 -- utils/src/com/cloud/utils/Pair.java | 87 - .../src/com/cloud/utils/PasswordGenerator.java | 90 - utils/src/com/cloud/utils/Predicate.java | 24 - utils/src/com/cloud/utils/ProcessUtil.java | 112 -- utils/src/com/cloud/utils/Profiler.java | 91 - utils/src/com/cloud/utils/PropertiesUtil.java | 196 --- utils/src/com/cloud/utils/ReflectUtil.java | 213 --- utils/src/com/cloud/utils/ReflectionUse.java | 31 - utils/src/com/cloud/utils/S3Utils.java | 603 ------- utils/src/com/cloud/utils/SerialVersionUID.java | 69 - utils/src/com/cloud/utils/StringUtils.java | 323 ---- utils/src/com/cloud/utils/SwiftUtil.java | 239 --- utils/src/com/cloud/utils/Ternary.java | 85 - utils/src/com/cloud/utils/UriUtils.java | 394 ----- .../cloud/utils/UsernamePasswordValidator.java | 49 - utils/src/com/cloud/utils/UuidUtils.java | 34 - .../cloud/utils/backoff/BackoffAlgorithm.java | 38 - .../utils/backoff/impl/ConstantTimeBackoff.java | 102 -- .../backoff/impl/ConstantTimeBackoffMBean.java | 35 - .../utils/cisco/n1kv/vsm/NetconfHelper.java | 355 ---- .../cloud/utils/cisco/n1kv/vsm/PolicyMap.java | 34 - .../cloud/utils/cisco/n1kv/vsm/PortProfile.java | 48 - .../cloud/utils/cisco/n1kv/vsm/VsmCommand.java | 999 ----------- .../utils/cisco/n1kv/vsm/VsmOkResponse.java | 44 - .../cisco/n1kv/vsm/VsmPolicyMapResponse.java | 84 - .../cisco/n1kv/vsm/VsmPortProfileResponse.java | 166 -- .../cloud/utils/cisco/n1kv/vsm/VsmResponse.java | 222 --- .../src/com/cloud/utils/component/Adapter.java | 27 - .../com/cloud/utils/component/AdapterBase.java | 40 - .../com/cloud/utils/component/AdapterList.java | 37 - .../cloud/utils/component/ComponentContext.java | 282 ---- .../ComponentInstantiationPostProcessor.java | 149 -- .../utils/component/ComponentLifecycle.java | 64 - .../utils/component/ComponentLifecycleBase.java | 87 - .../component/ComponentMethodInterceptable.java | 27 - .../component/ComponentMethodInterceptor.java | 32 - .../utils/component/ComponentNamingPolicy.java | 65 - .../src/com/cloud/utils/component/Manager.java | 27 - .../com/cloud/utils/component/ManagerBase.java | 28 - utils/src/com/cloud/utils/component/Named.java | 26 - .../cloud/utils/component/PluggableService.java | 29 - .../src/com/cloud/utils/component/Registry.java | 51 - .../utils/component/SystemIntegrityChecker.java | 30 - .../utils/concurrency/NamedThreadFactory.java | 38 - .../com/cloud/utils/concurrency/Scheduler.java | 31 - .../utils/concurrency/SynchronizationEvent.java | 89 - .../com/cloud/utils/concurrency/TestClock.java | 161 -- .../com/cloud/utils/crypt/DBEncryptionUtil.java | 87 - .../utils/crypt/EncryptionSecretKeyChecker.java | 146 -- .../utils/crypt/EncryptionSecretKeySender.java | 65 - utils/src/com/cloud/utils/crypt/RSAHelper.java | 90 - utils/src/com/cloud/utils/db/DbProperties.java | 109 -- utils/src/com/cloud/utils/db/EntityManager.java | 84 - utils/src/com/cloud/utils/db/UUIDManager.java | 48 - .../com/cloud/utils/encoding/URLEncoder.java | 113 -- utils/src/com/cloud/utils/events/EventArgs.java | 44 - .../com/cloud/utils/events/SubscriptionMgr.java | 164 -- .../utils/exception/CSExceptionErrorCode.java | 100 -- .../utils/exception/CloudRuntimeException.java | 141 -- .../com/cloud/utils/exception/ErrorContext.java | 31 - .../utils/exception/ExceptionProxyObject.java | 55 - .../cloud/utils/exception/ExceptionUtil.java | 54 - .../utils/exception/ExecutionException.java | 49 - .../HypervisorVersionChangedException.java | 35 - utils/src/com/cloud/utils/fsm/ChangeEvent.java | 24 - utils/src/com/cloud/utils/fsm/FiniteState.java | 58 - utils/src/com/cloud/utils/fsm/FiniteState2.java | 34 - .../com/cloud/utils/fsm/FiniteStateObject.java | 25 - .../cloud/utils/fsm/NoTransitionException.java | 36 - utils/src/com/cloud/utils/fsm/State.java | 27 - utils/src/com/cloud/utils/fsm/StateDao.java | 25 - .../src/com/cloud/utils/fsm/StateListener.java | 43 - utils/src/com/cloud/utils/fsm/StateMachine.java | 147 -- .../src/com/cloud/utils/fsm/StateMachine2.java | 261 --- utils/src/com/cloud/utils/fsm/StateObject.java | 27 - .../cloud/utils/log/CglibThrowableRenderer.java | 84 - utils/src/com/cloud/utils/mgmt/JmxUtil.java | 90 - .../com/cloud/utils/mgmt/ManagementBean.java | 27 - .../utils/mgmt/PropertyMapDynamicBean.java | 120 -- utils/src/com/cloud/utils/net/Ip.java | 98 -- utils/src/com/cloud/utils/net/Ip4Address.java | 80 - utils/src/com/cloud/utils/net/MacAddress.java | 367 ----- utils/src/com/cloud/utils/net/NetUtils.java | 1550 ------------------ utils/src/com/cloud/utils/net/NfsUtils.java | 55 - utils/src/com/cloud/utils/net/UrlUtil.java | 63 - .../src/com/cloud/utils/nio/HandlerFactory.java | 28 - utils/src/com/cloud/utils/nio/Link.java | 567 ------- utils/src/com/cloud/utils/nio/NioClient.java | 125 -- .../src/com/cloud/utils/nio/NioConnection.java | 476 ------ utils/src/com/cloud/utils/nio/NioServer.java | 97 -- utils/src/com/cloud/utils/nio/Task.java | 89 - .../com/cloud/utils/nio/TrustAllManager.java | 45 - .../BasicEncodedRESTValidationStrategy.java | 66 - .../utils/rest/CloudstackRESTException.java | 39 - .../cloud/utils/rest/RESTServiceConnector.java | 395 ----- .../utils/rest/RESTValidationStrategy.java | 165 -- .../cloud/utils/script/OutputInterpreter.java | 141 -- utils/src/com/cloud/utils/script/Script.java | 502 ------ utils/src/com/cloud/utils/script/Script2.java | 70 - .../cloud/utils/security/CertificateHelper.java | 166 -- utils/src/com/cloud/utils/ssh/SSHCmdHelper.java | 179 -- .../src/com/cloud/utils/ssh/SSHKeysHelper.java | 115 -- utils/src/com/cloud/utils/ssh/SshException.java | 30 - utils/src/com/cloud/utils/ssh/SshHelper.java | 209 --- .../storage/encoding/DecodedDataObject.java | 56 - .../storage/encoding/DecodedDataStore.java | 68 - .../cloud/utils/storage/encoding/Decoder.java | 66 - .../utils/storage/encoding/EncodingType.java | 32 - .../com/cloud/utils/time/InaccurateClock.java | 102 -- .../cloud/utils/time/InaccurateClockMBean.java | 28 - .../com/cloud/utils/xmlobject/XmlObject.java | 214 --- .../cloud/utils/xmlobject/XmlObjectParser.java | 128 -- .../src/main/java/com/cloud/maint/Version.java | 77 + .../java/com/cloud/utils/ActionDelegate.java | 24 + .../java/com/cloud/utils/AutoCloseableUtil.java | 36 + .../com/cloud/utils/CloudResourceBundle.java | 48 + .../com/cloud/utils/ConstantTimeComparator.java | 42 + .../src/main/java/com/cloud/utils/DateUtil.java | 274 ++++ .../java/com/cloud/utils/EncryptionUtil.java | 73 + .../main/java/com/cloud/utils/EnumUtils.java | 58 + .../java/com/cloud/utils/ExecutionResult.java | 46 + .../src/main/java/com/cloud/utils/FileUtil.java | 32 + .../main/java/com/cloud/utils/HttpUtils.java | 114 ++ .../main/java/com/cloud/utils/IteratorUtil.java | 72 + .../src/main/java/com/cloud/utils/Journal.java | 104 ++ .../src/main/java/com/cloud/utils/LogUtils.java | 45 + .../java/com/cloud/utils/MethodCapturer.java | 113 ++ .../main/java/com/cloud/utils/NumbersUtil.java | 139 ++ utils/src/main/java/com/cloud/utils/Pair.java | 87 + .../java/com/cloud/utils/PasswordGenerator.java | 90 + .../main/java/com/cloud/utils/Predicate.java | 24 + .../main/java/com/cloud/utils/ProcessUtil.java | 112 ++ .../src/main/java/com/cloud/utils/Profiler.java | 91 + .../java/com/cloud/utils/PropertiesUtil.java | 196 +++ .../main/java/com/cloud/utils/ReflectUtil.java | 213 +++ .../java/com/cloud/utils/ReflectionUse.java | 31 + .../src/main/java/com/cloud/utils/S3Utils.java | 603 +++++++ .../java/com/cloud/utils/SerialVersionUID.java | 69 + .../main/java/com/cloud/utils/StringUtils.java | 323 ++++ .../main/java/com/cloud/utils/SwiftUtil.java | 239 +++ .../src/main/java/com/cloud/utils/Ternary.java | 85 + .../src/main/java/com/cloud/utils/UriUtils.java | 394 +++++ .../cloud/utils/UsernamePasswordValidator.java | 49 + .../main/java/com/cloud/utils/UuidUtils.java | 34 + .../cloud/utils/backoff/BackoffAlgorithm.java | 38 + .../utils/backoff/impl/ConstantTimeBackoff.java | 102 ++ .../backoff/impl/ConstantTimeBackoffMBean.java | 35 + .../utils/cisco/n1kv/vsm/NetconfHelper.java | 355 ++++ .../cloud/utils/cisco/n1kv/vsm/PolicyMap.java | 34 + .../cloud/utils/cisco/n1kv/vsm/PortProfile.java | 48 + .../cloud/utils/cisco/n1kv/vsm/VsmCommand.java | 999 +++++++++++ .../utils/cisco/n1kv/vsm/VsmOkResponse.java | 44 + .../cisco/n1kv/vsm/VsmPolicyMapResponse.java | 84 + .../cisco/n1kv/vsm/VsmPortProfileResponse.java | 166 ++ .../cloud/utils/cisco/n1kv/vsm/VsmResponse.java | 222 +++ .../java/com/cloud/utils/component/Adapter.java | 27 + .../com/cloud/utils/component/AdapterBase.java | 40 + .../com/cloud/utils/component/AdapterList.java | 37 + .../cloud/utils/component/ComponentContext.java | 282 ++++ .../ComponentInstantiationPostProcessor.java | 149 ++ .../utils/component/ComponentLifecycle.java | 64 + .../utils/component/ComponentLifecycleBase.java | 87 + .../component/ComponentMethodInterceptable.java | 27 + .../component/ComponentMethodInterceptor.java | 32 + .../utils/component/ComponentNamingPolicy.java | 65 + .../java/com/cloud/utils/component/Manager.java | 27 + .../com/cloud/utils/component/ManagerBase.java | 28 + .../java/com/cloud/utils/component/Named.java | 26 + .../cloud/utils/component/PluggableService.java | 29 + .../com/cloud/utils/component/Registry.java | 51 + .../utils/component/SystemIntegrityChecker.java | 30 + .../utils/concurrency/NamedThreadFactory.java | 38 + .../com/cloud/utils/concurrency/Scheduler.java | 31 + .../utils/concurrency/SynchronizationEvent.java | 89 + .../com/cloud/utils/concurrency/TestClock.java | 161 ++ .../com/cloud/utils/crypt/DBEncryptionUtil.java | 87 + .../utils/crypt/EncryptionSecretKeyChecker.java | 146 ++ .../utils/crypt/EncryptionSecretKeySender.java | 65 + .../java/com/cloud/utils/crypt/RSAHelper.java | 90 + .../java/com/cloud/utils/db/DbProperties.java | 109 ++ .../java/com/cloud/utils/db/EntityManager.java | 84 + .../java/com/cloud/utils/db/UUIDManager.java | 48 + .../com/cloud/utils/encoding/URLEncoder.java | 113 ++ .../java/com/cloud/utils/events/EventArgs.java | 44 + .../com/cloud/utils/events/SubscriptionMgr.java | 164 ++ .../utils/exception/CSExceptionErrorCode.java | 100 ++ .../utils/exception/CloudRuntimeException.java | 141 ++ .../com/cloud/utils/exception/ErrorContext.java | 31 + .../utils/exception/ExceptionProxyObject.java | 55 + .../cloud/utils/exception/ExceptionUtil.java | 54 + .../utils/exception/ExecutionException.java | 49 + .../HypervisorVersionChangedException.java | 35 + .../java/com/cloud/utils/fsm/ChangeEvent.java | 24 + .../java/com/cloud/utils/fsm/FiniteState.java | 58 + .../java/com/cloud/utils/fsm/FiniteState2.java | 34 + .../com/cloud/utils/fsm/FiniteStateObject.java | 25 + .../cloud/utils/fsm/NoTransitionException.java | 36 + .../main/java/com/cloud/utils/fsm/State.java | 27 + .../main/java/com/cloud/utils/fsm/StateDao.java | 25 + .../java/com/cloud/utils/fsm/StateListener.java | 43 + .../java/com/cloud/utils/fsm/StateMachine.java | 147 ++ .../java/com/cloud/utils/fsm/StateMachine2.java | 261 +++ .../java/com/cloud/utils/fsm/StateObject.java | 27 + .../main/java/com/cloud/utils/mgmt/JmxUtil.java | 90 + .../com/cloud/utils/mgmt/ManagementBean.java | 27 + .../utils/mgmt/PropertyMapDynamicBean.java | 120 ++ utils/src/main/java/com/cloud/utils/net/Ip.java | 98 ++ .../java/com/cloud/utils/net/Ip4Address.java | 80 + .../java/com/cloud/utils/net/MacAddress.java | 367 +++++ .../main/java/com/cloud/utils/net/NetUtils.java | 1550 ++++++++++++++++++ .../main/java/com/cloud/utils/net/NfsUtils.java | 55 + .../main/java/com/cloud/utils/net/UrlUtil.java | 63 + .../com/cloud/utils/nio/HandlerFactory.java | 28 + .../src/main/java/com/cloud/utils/nio/Link.java | 567 +++++++ .../java/com/cloud/utils/nio/NioClient.java | 125 ++ .../java/com/cloud/utils/nio/NioConnection.java | 476 ++++++ .../java/com/cloud/utils/nio/NioServer.java | 97 ++ .../src/main/java/com/cloud/utils/nio/Task.java | 89 + .../com/cloud/utils/nio/TrustAllManager.java | 45 + .../BasicEncodedRESTValidationStrategy.java | 66 + .../utils/rest/CloudstackRESTException.java | 39 + .../cloud/utils/rest/RESTServiceConnector.java | 395 +++++ .../utils/rest/RESTValidationStrategy.java | 165 ++ .../cloud/utils/script/OutputInterpreter.java | 141 ++ .../java/com/cloud/utils/script/Script.java | 502 ++++++ .../java/com/cloud/utils/script/Script2.java | 70 + .../cloud/utils/security/CertificateHelper.java | 166 ++ .../java/com/cloud/utils/ssh/SSHCmdHelper.java | 179 ++ .../java/com/cloud/utils/ssh/SSHKeysHelper.java | 115 ++ .../java/com/cloud/utils/ssh/SshException.java | 30 + .../java/com/cloud/utils/ssh/SshHelper.java | 209 +++ .../storage/encoding/DecodedDataObject.java | 56 + .../storage/encoding/DecodedDataStore.java | 68 + .../cloud/utils/storage/encoding/Decoder.java | 66 + .../utils/storage/encoding/EncodingType.java | 32 + .../com/cloud/utils/time/InaccurateClock.java | 102 ++ .../cloud/utils/time/InaccurateClockMBean.java | 28 + .../com/cloud/utils/xmlobject/XmlObject.java | 214 +++ .../cloud/utils/xmlobject/XmlObjectParser.java | 128 ++ .../utils/baremetal/BaremetalUtils.java | 24 + .../utils/graphite/GraphiteClient.java | 123 ++ .../utils/graphite/GraphiteException.java | 31 + .../utils/identity/ManagementServerNode.java | 63 + .../utils/imagestore/ImageStoreUtil.java | 110 ++ .../cloudstack/utils/security/SSLUtils.java | 58 + .../utils/security/SecureSSLSocketFactory.java | 124 ++ .../cloudstack/utils/usage/UsageUtils.java | 24 + .../ssl/EasySSLProtocolSocketFactory.java | 210 +++ .../contrib/ssl/EasyX509TrustManager.java | 110 ++ utils/src/main/resources/cloud.keystore | Bin 0 -> 1316 bytes .../utils/baremetal/BaremetalUtils.java | 24 - .../utils/graphite/GraphiteClient.java | 123 -- .../utils/graphite/GraphiteException.java | 31 - .../utils/identity/ManagementServerNode.java | 63 - .../utils/imagestore/ImageStoreUtil.java | 110 -- .../cloudstack/utils/security/SSLUtils.java | 58 - .../utils/security/SecureSSLSocketFactory.java | 124 -- .../cloudstack/utils/usage/UsageUtils.java | 24 - .../ssl/EasySSLProtocolSocketFactory.java | 210 --- .../contrib/ssl/EasyX509TrustManager.java | 110 -- .../test/java/com/cloud/utils/DateUtilTest.java | 60 + .../test/java/com/cloud/utils/DummyImpl.java | 31 + .../java/com/cloud/utils/DummyInterface.java | 24 + .../java/com/cloud/utils/DummyPremiumImpl.java | 28 + .../java/com/cloud/utils/HttpUtilsTest.java | 94 ++ .../java/com/cloud/utils/NumbersUtilTest.java | 47 + .../com/cloud/utils/PasswordGeneratorTest.java | 42 + .../java/com/cloud/utils/ProcessUtilTest.java | 76 + .../com/cloud/utils/PropertiesUtilsTest.java | 64 + .../java/com/cloud/utils/ReflectUtilTest.java | 148 ++ .../test/java/com/cloud/utils/ScriptTest.java | 135 ++ .../java/com/cloud/utils/StringUtilsTest.java | 253 +++ .../test/java/com/cloud/utils/TernaryTest.java | 34 + .../test/java/com/cloud/utils/TestProfiler.java | 116 ++ .../test/java/com/cloud/utils/UriUtilsTest.java | 60 + .../java/com/cloud/utils/UuidUtilsTest.java | 42 + .../backoff/impl/ConstantTimeBackoffTest.java | 112 ++ .../crypto/EncryptionSecretKeyCheckerTest.java | 45 + .../com/cloud/utils/crypto/RSAHelperTest.java | 54 + .../cloud/utils/encoding/UrlEncoderTest.java | 33 + .../utils/exception/ExceptionUtilTest.java | 52 + .../com/cloud/utils/net/Ip4AddressTest.java | 40 + .../test/java/com/cloud/utils/net/IpTest.java | 63 + .../com/cloud/utils/net/MacAddressTest.java | 60 + .../java/com/cloud/utils/net/NetUtilsTest.java | 421 +++++ .../utils/rest/RESTServiceConnectorTest.java | 395 +++++ .../com/cloud/utils/ssh/SSHKeysHelperTest.java | 73 + .../utils/testcase/Log4jEnabledTestCase.java | 58 + .../java/com/cloud/utils/testcase/NioTest.java | 216 +++ .../cloud/utils/xmlobject/TestXmlObject.java | 53 + .../cloud/utils/xmlobject/TestXmlObject2.java | 54 + .../utils/imagestore/ImageStoreUtilTest.java | 54 + .../com/cloud/utils/QualifierTestContext.xml | 38 + .../utils/db/transactionContextBuilderTest.xml | 48 + utils/src/test/resources/log4j.xml | 118 ++ utils/src/test/resources/testContext.xml | 52 + utils/test/com/cloud/utils/DateUtilTest.java | 60 - utils/test/com/cloud/utils/DummyImpl.java | 31 - utils/test/com/cloud/utils/DummyInterface.java | 24 - .../test/com/cloud/utils/DummyPremiumImpl.java | 28 - utils/test/com/cloud/utils/HttpUtilsTest.java | 94 -- utils/test/com/cloud/utils/NumbersUtilTest.java | 47 - .../com/cloud/utils/PasswordGeneratorTest.java | 42 - utils/test/com/cloud/utils/ProcessUtilTest.java | 76 - .../com/cloud/utils/PropertiesUtilsTest.java | 64 - utils/test/com/cloud/utils/ReflectUtilTest.java | 148 -- utils/test/com/cloud/utils/ScriptTest.java | 135 -- utils/test/com/cloud/utils/StringUtilsTest.java | 253 --- utils/test/com/cloud/utils/TernaryTest.java | 34 - utils/test/com/cloud/utils/TestProfiler.java | 116 -- utils/test/com/cloud/utils/UriUtilsTest.java | 60 - utils/test/com/cloud/utils/UuidUtilsTest.java | 42 - .../backoff/impl/ConstantTimeBackoffTest.java | 112 -- .../crypto/EncryptionSecretKeyCheckerTest.java | 45 - .../com/cloud/utils/crypto/RSAHelperTest.java | 54 - .../cloud/utils/encoding/UrlEncoderTest.java | 33 - .../utils/exception/ExceptionUtilTest.java | 52 - .../com/cloud/utils/net/Ip4AddressTest.java | 40 - utils/test/com/cloud/utils/net/IpTest.java | 63 - .../com/cloud/utils/net/MacAddressTest.java | 60 - .../test/com/cloud/utils/net/NetUtilsTest.java | 421 ----- .../utils/rest/RESTServiceConnectorTest.java | 395 ----- .../com/cloud/utils/ssh/SSHKeysHelperTest.java | 73 - .../utils/testcase/Log4jEnabledTestCase.java | 58 - .../test/com/cloud/utils/testcase/NioTest.java | 216 --- .../cloud/utils/xmlobject/TestXmlObject.java | 53 - .../cloud/utils/xmlobject/TestXmlObject2.java | 54 - .../utils/imagestore/ImageStoreUtilTest.java | 54 - .../com/cloud/utils/QualifierTestContext.xml | 38 - .../utils/db/transactionContextBuilderTest.xml | 48 - utils/test/resources/log4j.xml | 118 -- utils/test/resources/testContext.xml | 52 - 350 files changed, 20350 insertions(+), 20426 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/certs/cloud.keystore ---------------------------------------------------------------------- diff --git a/utils/certs/cloud.keystore b/utils/certs/cloud.keystore deleted file mode 100644 index 33d7777..0000000 Binary files a/utils/certs/cloud.keystore and /dev/null differ http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/pom.xml ---------------------------------------------------------------------- diff --git a/utils/pom.xml b/utils/pom.xml index 937dc08..d01f6ff 100755 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -18,7 +18,8 @@ under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>cloud-utils</artifactId> <name>Apache CloudStack Utils</name> @@ -96,8 +97,8 @@ <artifactId>ejb-api</artifactId> </dependency> <dependency> - <groupId>com.googlecode.java-ipv6</groupId> - <artifactId>java-ipv6</artifactId> + <groupId>com.googlecode.java-ipv6</groupId> + <artifactId>java-ipv6</artifactId> </dependency> <dependency> <groupId>commons-configuration</groupId> @@ -115,10 +116,10 @@ <scope>test</scope> </dependency> <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <scope>provided</scope> - <version>${cs.commons-io.version}</version> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <scope>provided</scope> + <version>${cs.commons-io.version}</version> </dependency> <dependency> <groupId>org.reflections</groupId> @@ -154,9 +155,9 @@ <version>${cs.opensaml.version}</version> </dependency> <dependency> - <groupId>commons-net</groupId> - <artifactId>commons-net</artifactId> - <version>3.3</version> + <groupId>commons-net</groupId> + <artifactId>commons-net</artifactId> + <version>3.3</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> @@ -169,6 +170,20 @@ </dependency> </dependencies> <build> + <sourceDirectory>src/main/java</sourceDirectory> + <testSourceDirectory>src/test/java</testSourceDirectory> + <outputDirectory>target/classes</outputDirectory> + <testOutputDirectory>target/test-classes</testOutputDirectory> + <resources> + <resource> + <directory>src/main/resources</directory> + </resource> + </resources> + <testResources> + <testResource> + <directory>src/test/resources</directory> + </testResource> + </testResources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> @@ -191,15 +206,9 @@ <exclude>com/cloud/utils/testcase/NioTest.java</exclude> </excludes> </configuration> - </plugin> + </plugin> </plugins> - <resources> - <resource> - <directory>certs</directory> - </resource> - </resources> </build> - <profiles> <profile> <id>integration</id> @@ -221,5 +230,4 @@ </build> </profile> </profiles> - </project> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/maint/Version.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/maint/Version.java b/utils/src/com/cloud/maint/Version.java deleted file mode 100644 index 925806e..0000000 --- a/utils/src/com/cloud/maint/Version.java +++ /dev/null @@ -1,77 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.maint; - -public class Version { - /** - * Compares two version strings and see which one is higher version. - * @param ver1 - * @param ver2 - * @return positive if ver1 is higher. negative if ver1 is lower; zero if the same. - */ - public static int compare(String ver1, String ver2) { - String[] tokens1 = ver1.split("[.]"); - String[] tokens2 = ver2.split("[.]"); -// assert(tokens1.length <= tokens2.length); - - int compareLength = Math.min(tokens1.length, tokens2.length); - for (int i = 0; i < compareLength; i++) { - long version1 = Long.parseLong(tokens1[i]); - long version2 = Long.parseLong(tokens2[i]); - if (version1 != version2) { - return version1 < version2 ? -1 : 1; - } - } - - if (tokens1.length > tokens2.length) { - return 1; - } else if (tokens1.length < tokens2.length) { - return -1; - } - - return 0; - } - - public static String trimToPatch(String version) { - int index = version.indexOf("-"); - - if (index > 0) - version = version.substring(0, index); - - String[] tokens = version.split("[.]"); - - if (tokens.length < 3) - return "0"; - return tokens[0] + "." + tokens[1] + "." + tokens[2]; - } - - public static String trimRouterVersion(String version) { - String[] tokens = version.split(" "); - if (tokens.length >= 3 && tokens[2].matches("[0-9]+(\\.[0-9]+)*")) { - return tokens[2]; - } - return "0"; - } - - public static void main(String[] args) { - System.out.println("Result is " + compare(args[0], args[1])); - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/ActionDelegate.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/ActionDelegate.java b/utils/src/com/cloud/utils/ActionDelegate.java deleted file mode 100644 index 02f76d9..0000000 --- a/utils/src/com/cloud/utils/ActionDelegate.java +++ /dev/null @@ -1,24 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -public interface ActionDelegate<T> { - void action(T param); -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/AutoCloseableUtil.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/AutoCloseableUtil.java b/utils/src/com/cloud/utils/AutoCloseableUtil.java deleted file mode 100644 index f93265b..0000000 --- a/utils/src/com/cloud/utils/AutoCloseableUtil.java +++ /dev/null @@ -1,36 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.utils; - -import org.apache.log4j.Logger; - -public class AutoCloseableUtil { - private final static Logger s_logger = Logger.getLogger(AutoCloseableUtil.class); - - public static void closeAutoCloseable(AutoCloseable ac, String message) { - try { - - if (ac != null) { - ac.close(); - } - - } catch (Exception e) { - s_logger.warn("[ignored] " + message, e); - } - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/CloudResourceBundle.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/CloudResourceBundle.java b/utils/src/com/cloud/utils/CloudResourceBundle.java deleted file mode 100644 index cf27d79..0000000 --- a/utils/src/com/cloud/utils/CloudResourceBundle.java +++ /dev/null @@ -1,48 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.util.Locale; -import java.util.ResourceBundle; - -public class CloudResourceBundle { - - private ResourceBundle _bundle; - - public CloudResourceBundle(ResourceBundle bundle) { - _bundle = bundle; - } - - public static CloudResourceBundle getBundle(String baseName, Locale locale) { - return new CloudResourceBundle(ResourceBundle.getBundle(baseName, locale)); - } - - private String getString(String key) { - try { - return _bundle.getString(key); - } catch (Exception e) { - return key; //if translation is not found, just return original word (i.e. English). - } - } - - public String t(String key) { - return getString(key); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/ConstantTimeComparator.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/ConstantTimeComparator.java b/utils/src/com/cloud/utils/ConstantTimeComparator.java deleted file mode 100644 index baf2bc2..0000000 --- a/utils/src/com/cloud/utils/ConstantTimeComparator.java +++ /dev/null @@ -1,42 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.nio.charset.Charset; - -public class ConstantTimeComparator { - - public static boolean compareBytes(byte[] b1, byte[] b2) { - if (b1.length != b2.length) { - return false; - } - - int result = 0; - for (int i = 0; i < b1.length; i++) { - result |= b1[i] ^ b2[i]; - } - return result == 0; - } - - public static boolean compareStrings(String s1, String s2) { - final Charset encoding = Charset.forName("UTF-8"); - return compareBytes(s1.getBytes(encoding), s2.getBytes(encoding)); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/DateUtil.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/DateUtil.java b/utils/src/com/cloud/utils/DateUtil.java deleted file mode 100644 index 7787e1b..0000000 --- a/utils/src/com/cloud/utils/DateUtil.java +++ /dev/null @@ -1,274 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.TimeZone; - -import com.cloud.utils.exception.CloudRuntimeException; - -public class DateUtil { - public static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT"); - public static final String YYYYMMDD_FORMAT = "yyyyMMddHHmmss"; - private static final DateFormat s_outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); - - public static Date currentGMTTime() { - // Date object always stores miliseconds offset based on GMT internally - return new Date(); - } - - // yyyy-MM-ddTHH:mm:ssZxxxx - public static Date parseTZDateString(String str) throws ParseException { - DateFormat dfParse = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'Z"); - return dfParse.parse(str); - } - - public static Date parseDateString(TimeZone tz, String dateString) { - return parseDateString(tz, dateString, "yyyy-MM-dd HH:mm:ss"); - } - - public static Date parseDateString(TimeZone tz, String dateString, String formatString) { - DateFormat df = new SimpleDateFormat(formatString); - df.setTimeZone(tz); - - try { - return df.parse(dateString); - } catch (ParseException e) { - throw new CloudRuntimeException("why why ", e); - } - } - - public static String displayDateInTimezone(TimeZone tz, Date time) { - return getDateDisplayString(tz, time, "yyyy-MM-dd HH:mm:ss z"); - } - - public static String getDateDisplayString(TimeZone tz, Date time) { - return getDateDisplayString(tz, time, "yyyy-MM-dd HH:mm:ss"); - } - - public static String getDateDisplayString(TimeZone tz, Date time, String formatString) { - DateFormat df = new SimpleDateFormat(formatString); - df.setTimeZone(tz); - - return df.format(time); - } - - public static String getOutputString(Date date) { - if (date == null) { - return ""; - } - String formattedString = null; - synchronized (s_outputFormat) { - formattedString = s_outputFormat.format(date); - } - return formattedString; - } - - public static Date now() { - return new Date(System.currentTimeMillis()); - } - - public enum IntervalType { - HOURLY, DAILY, WEEKLY, MONTHLY; - - boolean equals(String intervalType) { - return super.toString().equalsIgnoreCase(intervalType); - } - - public static IntervalType getIntervalType(String intervalTypeStr) { - for (IntervalType intervalType : IntervalType.values()) { - if (intervalType.equals(intervalTypeStr)) { - return intervalType; - } - } - return null; - } - } - - public static IntervalType getIntervalType(short type) { - if (type < 0 || type >= IntervalType.values().length) { - return null; - } - return IntervalType.values()[type]; - } - - /** - * Return next run time - * @param intervalType hourly/daily/weekly/monthly - * @param schedule MM[:HH][:DD] format. DD is day of week for weekly and day of month for monthly - * @param timezone The timezone in which the schedule string is specified - * @param startDate if specified, returns next run time after the specified startDate - * @return - */ - public static Date getNextRunTime(IntervalType type, String schedule, String timezone, Date startDate) { - - String[] scheduleParts = schedule.split(":"); //MM:HH:DAY - - final Calendar scheduleTime = Calendar.getInstance(); - scheduleTime.setTimeZone(TimeZone.getTimeZone(timezone)); - - if (startDate == null) { - startDate = new Date(); - } - scheduleTime.setTime(startDate); - // Throw an ArrayIndexOutOfBoundsException if schedule is badly formatted. - scheduleTime.setLenient(false); - int minutes = 0; - int hour = 0; - int day = 0; - Date execDate = null; - - switch (type) { - case HOURLY: - if (scheduleParts.length < 1) { - throw new CloudRuntimeException("Incorrect schedule format: " + schedule + " for interval type:" + type.toString()); - } - minutes = Integer.parseInt(scheduleParts[0]); - scheduleTime.set(Calendar.MINUTE, minutes); - scheduleTime.set(Calendar.SECOND, 0); - scheduleTime.set(Calendar.MILLISECOND, 0); - try { - execDate = scheduleTime.getTime(); - } catch (IllegalArgumentException ex) { - scheduleTime.setLenient(true); - execDate = scheduleTime.getTime(); - scheduleTime.setLenient(false); - } - // XXX: !execDate.after(startDate) is strictly for testing. - // During testing we use a test clock which runs much faster than the real clock - // So startDate and execDate will always be ahead in the future - // and we will never increase the time here - if (execDate.before(new Date()) || !execDate.after(startDate)) { - scheduleTime.add(Calendar.HOUR_OF_DAY, 1); - } - break; - case DAILY: - if (scheduleParts.length < 2) { - throw new CloudRuntimeException("Incorrect schedule format: " + schedule + " for interval type:" + type.toString()); - } - minutes = Integer.parseInt(scheduleParts[0]); - hour = Integer.parseInt(scheduleParts[1]); - - scheduleTime.set(Calendar.HOUR_OF_DAY, hour); - scheduleTime.set(Calendar.MINUTE, minutes); - scheduleTime.set(Calendar.SECOND, 0); - scheduleTime.set(Calendar.MILLISECOND, 0); - try { - execDate = scheduleTime.getTime(); - } catch (IllegalArgumentException ex) { - scheduleTime.setLenient(true); - execDate = scheduleTime.getTime(); - scheduleTime.setLenient(false); - } - // XXX: !execDate.after(startDate) is strictly for testing. - // During testing we use a test clock which runs much faster than the real clock - // So startDate and execDate will always be ahead in the future - // and we will never increase the time here - if (execDate.before(new Date()) || !execDate.after(startDate)) { - scheduleTime.add(Calendar.DAY_OF_YEAR, 1); - } - break; - case WEEKLY: - if (scheduleParts.length < 3) { - throw new CloudRuntimeException("Incorrect schedule format: " + schedule + " for interval type:" + type.toString()); - } - minutes = Integer.parseInt(scheduleParts[0]); - hour = Integer.parseInt(scheduleParts[1]); - day = Integer.parseInt(scheduleParts[2]); - scheduleTime.set(Calendar.DAY_OF_WEEK, day); - scheduleTime.set(Calendar.HOUR_OF_DAY, hour); - scheduleTime.set(Calendar.MINUTE, minutes); - scheduleTime.set(Calendar.SECOND, 0); - scheduleTime.set(Calendar.MILLISECOND, 0); - try { - execDate = scheduleTime.getTime(); - } catch (IllegalArgumentException ex) { - scheduleTime.setLenient(true); - execDate = scheduleTime.getTime(); - scheduleTime.setLenient(false); - } - // XXX: !execDate.after(startDate) is strictly for testing. - // During testing we use a test clock which runs much faster than the real clock - // So startDate and execDate will always be ahead in the future - // and we will never increase the time here - if (execDate.before(new Date()) || !execDate.after(startDate)) { - scheduleTime.add(Calendar.DAY_OF_WEEK, 7); - } - ; - break; - case MONTHLY: - if (scheduleParts.length < 3) { - throw new CloudRuntimeException("Incorrect schedule format: " + schedule + " for interval type:" + type.toString()); - } - minutes = Integer.parseInt(scheduleParts[0]); - hour = Integer.parseInt(scheduleParts[1]); - day = Integer.parseInt(scheduleParts[2]); - if (day > 28) { - throw new CloudRuntimeException("Day cannot be greater than 28 for monthly schedule"); - } - scheduleTime.set(Calendar.DAY_OF_MONTH, day); - scheduleTime.set(Calendar.HOUR_OF_DAY, hour); - scheduleTime.set(Calendar.MINUTE, minutes); - scheduleTime.set(Calendar.SECOND, 0); - scheduleTime.set(Calendar.MILLISECOND, 0); - try { - execDate = scheduleTime.getTime(); - } catch (IllegalArgumentException ex) { - scheduleTime.setLenient(true); - execDate = scheduleTime.getTime(); - scheduleTime.setLenient(false); - } - // XXX: !execDate.after(startDate) is strictly for testing. - // During testing we use a test clock which runs much faster than the real clock - // So startDate and execDate will always be ahead in the future - // and we will never increase the time here - if (execDate.before(new Date()) || !execDate.after(startDate)) { - scheduleTime.add(Calendar.MONTH, 1); - } - break; - default: - throw new CloudRuntimeException("Incorrect interval: " + type.toString()); - } - - try { - return scheduleTime.getTime(); - } catch (IllegalArgumentException ex) { - scheduleTime.setLenient(true); - Date nextScheduledDate = scheduleTime.getTime(); - scheduleTime.setLenient(false); - return nextScheduledDate; - } - } - - public static long getTimeDifference(Date date1, Date date2){ - - Calendar dateCalendar1 = Calendar.getInstance(); - dateCalendar1.setTime(date1); - Calendar dateCalendar2 = Calendar.getInstance(); - dateCalendar2.setTime(date2); - - return (dateCalendar1.getTimeInMillis() - dateCalendar2.getTimeInMillis() )/1000; - - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/EncryptionUtil.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/EncryptionUtil.java b/utils/src/com/cloud/utils/EncryptionUtil.java deleted file mode 100644 index b82842e..0000000 --- a/utils/src/com/cloud/utils/EncryptionUtil.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.cloud.utils; - -import java.io.UnsupportedEncodingException; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; -import org.jasypt.encryption.pbe.PBEStringEncryptor; -import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; - -import com.cloud.utils.exception.CloudRuntimeException; - -public class EncryptionUtil { - public static final Logger s_logger = Logger.getLogger(EncryptionUtil.class.getName()); - private static PBEStringEncryptor encryptor; - - private static void initialize(String key) { - StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); - standardPBEStringEncryptor.setAlgorithm("PBEWITHSHA1ANDDESEDE"); - standardPBEStringEncryptor.setPassword(key); - encryptor = standardPBEStringEncryptor; - } - - public static String encodeData(String data, String key) { - if (encryptor == null) { - initialize(key); - } - return encryptor.encrypt(data); - } - - public static String decodeData(String encodedData, String key) { - if (encryptor == null) { - initialize(key); - } - return encryptor.decrypt(encodedData); - } - - public static String generateSignature(String data, String key) { - try { - final Mac mac = Mac.getInstance("HmacSHA1"); - final SecretKeySpec keySpec = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA1"); - mac.init(keySpec); - mac.update(data.getBytes("UTF-8")); - final byte[] encryptedBytes = mac.doFinal(); - return Base64.encodeBase64String(encryptedBytes); - } catch (NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException e) { - s_logger.error("exception occurred which encoding the data." + e.getMessage()); - throw new CloudRuntimeException("unable to generate signature", e); - } - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/EnumUtils.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/EnumUtils.java b/utils/src/com/cloud/utils/EnumUtils.java deleted file mode 100644 index 02b6a25..0000000 --- a/utils/src/com/cloud/utils/EnumUtils.java +++ /dev/null @@ -1,58 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -public class EnumUtils { - public static String listValues(Enum<?>[] enums) { - StringBuilder b = new StringBuilder("["); - - for (Enum<?> e : enums) { - b.append(e).append(", "); - } - b.append("]"); - return b.toString(); - } - - public static <T extends Enum<T>> T fromString(Class<T> clz, String value, T defaultVal) { - assert (clz != null); - - if (value != null) { - try { - return Enum.valueOf(clz, value.trim()); - } catch (IllegalArgumentException ex) { - assert (false); - } - } - return defaultVal; - } - - public static <T extends Enum<T>> T fromString(Class<T> clz, String value) { - assert (clz != null); - - if (value != null) { - try { - return Enum.valueOf(clz, value.trim()); - } catch (IllegalArgumentException ex) { - assert (false); - } - } - return null; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/ExecutionResult.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/ExecutionResult.java b/utils/src/com/cloud/utils/ExecutionResult.java deleted file mode 100644 index c8b620a..0000000 --- a/utils/src/com/cloud/utils/ExecutionResult.java +++ /dev/null @@ -1,46 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -public class ExecutionResult { - private Boolean success; - private String details; - - public ExecutionResult(Boolean success, String details) { - this.success = success; - this.details = details; - } - - public Boolean isSuccess() { - return success; - } - - public void setSuccess(Boolean success) { - this.success = success; - } - - public String getDetails() { - return details; - } - - public void setDetails(String details) { - this.details = details; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/FileUtil.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/FileUtil.java b/utils/src/com/cloud/utils/FileUtil.java deleted file mode 100644 index c55dd74..0000000 --- a/utils/src/com/cloud/utils/FileUtil.java +++ /dev/null @@ -1,32 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.io.File; -import java.io.IOException; - -import org.apache.commons.io.FileUtils; - -public class FileUtil { - - public static void copyfile(File source, File destination) throws IOException { - FileUtils.copyFile(source, destination); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/HttpUtils.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/HttpUtils.java b/utils/src/com/cloud/utils/HttpUtils.java deleted file mode 100644 index d2e844a..0000000 --- a/utils/src/com/cloud/utils/HttpUtils.java +++ /dev/null @@ -1,114 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import org.apache.log4j.Logger; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import java.io.IOException; -import java.util.Map; - -public class HttpUtils { - - public static final Logger s_logger = Logger.getLogger(HttpUtils.class); - - public static final String UTF_8 = "UTF-8"; - public static final String RESPONSE_TYPE_JSON = "json"; - public static final String RESPONSE_TYPE_XML = "xml"; - public static final String JSON_CONTENT_TYPE = "application/json; charset=UTF-8"; - public static final String XML_CONTENT_TYPE = "text/xml; charset=UTF-8"; - - public static void addSecurityHeaders(final HttpServletResponse resp) { - if (resp.containsHeader("X-Content-Type-Options")) { - resp.setHeader("X-Content-Type-Options", "nosniff"); - } - else { - resp.addHeader("X-Content-Type-Options", "nosniff"); - } - if (resp.containsHeader("X-XSS-Protection")) { - resp.setHeader("X-XSS-Protection", "1;mode=block"); - } - else { - resp.addHeader("X-XSS-Protection", "1;mode=block"); - } - } - - public static void writeHttpResponse(final HttpServletResponse resp, final String response, - final Integer responseCode, final String responseType, final String jsonContentType) { - try { - if (RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) { - if (jsonContentType != null && !jsonContentType.isEmpty()) { - resp.setContentType(jsonContentType); - } else { - resp.setContentType(JSON_CONTENT_TYPE); - } - } else if (RESPONSE_TYPE_XML.equalsIgnoreCase(responseType)){ - resp.setContentType(XML_CONTENT_TYPE); - } - if (responseCode != null) { - resp.setStatus(responseCode); - } - addSecurityHeaders(resp); - resp.getWriter().print(response); - } catch (final IOException ioex) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Exception writing http response: " + ioex); - } - } catch (final Exception ex) { - if (!(ex instanceof IllegalStateException)) { - s_logger.error("Unknown exception writing http response", ex); - } - } - } - - public static String findCookie(final Cookie[] cookies, final String key) { - if (cookies == null || key == null || key.isEmpty()) { - return null; - } - for (Cookie cookie: cookies) { - if (cookie != null && cookie.getName().equals(key)) { - return cookie.getValue(); - } - } - return null; - } - - public static boolean validateSessionKey(final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString) { - if (session == null || sessionKeyString == null) { - return false; - } - final String sessionKey = (String) session.getAttribute(sessionKeyString); - final String sessionKeyFromCookie = HttpUtils.findCookie(cookies, sessionKeyString); - String[] sessionKeyFromParams = null; - if (params != null) { - sessionKeyFromParams = (String[]) params.get(sessionKeyString); - } - if ((sessionKey == null) - || (sessionKeyFromParams == null && sessionKeyFromCookie == null) - || (sessionKeyFromParams != null && !sessionKey.equals(sessionKeyFromParams[0])) - || (sessionKeyFromCookie != null && !sessionKey.equals(sessionKeyFromCookie))) { - return false; - } - return true; - } - -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/IteratorUtil.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/IteratorUtil.java b/utils/src/com/cloud/utils/IteratorUtil.java deleted file mode 100644 index 8ab88f5..0000000 --- a/utils/src/com/cloud/utils/IteratorUtil.java +++ /dev/null @@ -1,72 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; - -public class IteratorUtil { - public static <T> Iterable<T> enumerationAsIterable(final Enumeration<T> e) { - return new Iterable<T>() { - @Override - public Iterator<T> iterator() { - return new Iterator<T>() { - @Override - public boolean hasNext() { - return e.hasMoreElements(); - } - - @Override - public T next() { - return e.nextElement(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - }; - } - - public static <T> Enumeration<T> iteratorAsEnumeration(final Iterator<T> it) { - return new Enumeration<T>() { - @Override - public boolean hasMoreElements() { - return it.hasNext(); - } - - @Override - public T nextElement() { - return it.next(); - } - }; - } - - public static <T extends Comparable<? super T>> List<T> asSortedList(Collection<T> c) { - List<T> list = new ArrayList<T>(c); - java.util.Collections.sort(list); - return list; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/Journal.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/Journal.java b/utils/src/com/cloud/utils/Journal.java deleted file mode 100644 index e88dba3..0000000 --- a/utils/src/com/cloud/utils/Journal.java +++ /dev/null @@ -1,104 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.util.ArrayList; - -import org.apache.log4j.Level; -import org.apache.log4j.Logger; - -/** - * Journal is used to kept what has happened during a process so someone can track - * what happens during a process. - * - */ -public class Journal { - String _name; - ArrayList<Pair<String, Object[]>> _entries; - - public Journal(String name) { - _name = name; - _entries = new ArrayList<Pair<String, Object[]>>(); - } - - final private void log(String msg, Object... params) { - Pair<String, Object[]> entry = new Pair<String, Object[]>(msg, params); - assert msg != null : "Message can not be null or else it's useless!"; - _entries.add(entry); - } - - public void record(String msg, Object... params) { - log(msg, params); - } - - public void record(Logger logger, Level p, String msg, Object... params) { - if (logger.isEnabledFor(p)) { - StringBuilder buf = new StringBuilder(); - toString(buf, msg, params); - String entry = buf.toString(); - log(entry); - logger.log(p, entry); - } else { - log(msg, params); - } - } - - protected void toString(StringBuilder buf, String msg, Object[] params) { - buf.append(msg); - if (params != null) { - buf.append(" - "); - int i = 0; - for (Object obj : params) { - buf.append('P').append(i).append('='); - buf.append(obj != null ? obj.toString() : "null"); - buf.append(", "); - } - buf.delete(buf.length() - 2, buf.length()); - } - } - - public String toString(String separator) { - StringBuilder buf = new StringBuilder(_name).append(": "); - for (Pair<String, Object[]> entry : _entries) { - toString(buf, entry.first(), entry.second()); - buf.append(separator); - } - return buf.toString(); - } - - @Override - public String toString() { - return toString("; "); - } - - public static class LogJournal extends Journal { - Logger _logger; - - public LogJournal(String name, Logger logger) { - super(name); - _logger = logger; - } - - @Override - public void record(String msg, Object... params) { - record(_logger, Level.DEBUG, msg, params); - } - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/LogUtils.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/LogUtils.java b/utils/src/com/cloud/utils/LogUtils.java deleted file mode 100644 index d86766c..0000000 --- a/utils/src/com/cloud/utils/LogUtils.java +++ /dev/null @@ -1,45 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.io.File; - -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; - -public class LogUtils { - public static final Logger s_logger = Logger.getLogger(LogUtils.class); - - public static void initLog4j(String log4jConfigFileName) { - assert (log4jConfigFileName != null); - File file = PropertiesUtil.findConfigFile(log4jConfigFileName); - if (file != null) { - s_logger.info("log4j configuration found at " + file.getAbsolutePath()); - DOMConfigurator.configureAndWatch(file.getAbsolutePath()); - } else { - String nameWithoutExtension = log4jConfigFileName.substring(0, log4jConfigFileName.lastIndexOf('.')); - file = PropertiesUtil.findConfigFile(nameWithoutExtension + ".properties"); - if (file != null) { - s_logger.info("log4j configuration found at " + file.getAbsolutePath()); - DOMConfigurator.configureAndWatch(file.getAbsolutePath()); - } - } - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/MethodCapturer.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/MethodCapturer.java b/utils/src/com/cloud/utils/MethodCapturer.java deleted file mode 100644 index 655a45d..0000000 --- a/utils/src/com/cloud/utils/MethodCapturer.java +++ /dev/null @@ -1,113 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.lang.reflect.Method; -import java.util.WeakHashMap; - -import net.sf.cglib.proxy.Callback; -import net.sf.cglib.proxy.CallbackFilter; -import net.sf.cglib.proxy.Enhancer; -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - -/* - * This helper class provides a way to retrieve Method in a strong-type way. It takes advantage of power of - * Intelligent IDE(Eclipse) in code-editing - * - * DummyImpl dummy = new DummyImpl(); - * MethodCapturer<DummyImpl> capturer = MethodCapturer.capture(dummy); - * Method method = capturer.get(capturer.instance().foo2()); - * - */ -public class MethodCapturer<T> { - - private final static int CACHE_SIZE = 1024; - - private T _instance; - private Method _method; - - private static WeakHashMap<Object, Object> s_cache = new WeakHashMap<Object, Object>(); - - private MethodCapturer() { - } - - @SuppressWarnings("unchecked") - public static <T> MethodCapturer<T> capture(T obj) { - synchronized (s_cache) { - MethodCapturer<T> capturer = (MethodCapturer<T>)s_cache.get(obj); - if (capturer != null) { - return capturer; - } - - final MethodCapturer<T> capturerNew = new MethodCapturer<T>(); - - Enhancer en = new Enhancer(); - en.setSuperclass(obj.getClass()); - en.setCallbacks(new Callback[] {new MethodInterceptor() { - @Override - public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable { - capturerNew.setMethod(arg1); - return null; - } - }, new MethodInterceptor() { - @Override - public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable { - return null; - } - }}); - en.setCallbackFilter(new CallbackFilter() { - @Override - public int accept(Method method) { - if (method.getParameterTypes().length == 0 && method.getName().equals("finalize")) { - return 1; - } - return 0; - } - }); - - capturerNew.setInstance((T)en.create()); - - // We expect MethodCapturer is only used for singleton objects here, so we only maintain a limited cache - // here - if (s_cache.size() < CACHE_SIZE) { - s_cache.put(obj, capturerNew); - } - - return capturerNew; - } - } - - public T instance() { - return _instance; - } - - private void setInstance(T instance) { - _instance = instance; - } - - public Method get(Object... useless) { - return _method; - } - - private void setMethod(Method method) { - _method = method; - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/NumbersUtil.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/NumbersUtil.java b/utils/src/com/cloud/utils/NumbersUtil.java deleted file mode 100644 index 8b93a40..0000000 --- a/utils/src/com/cloud/utils/NumbersUtil.java +++ /dev/null @@ -1,139 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.nio.ByteBuffer; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Formatter; -import java.util.Locale; - -import org.apache.commons.lang.math.NumberUtils; - -import com.cloud.utils.exception.CloudRuntimeException; - -public class NumbersUtil { - public static long parseLong(String s, long defaultValue) { - return NumberUtils.toLong(s, defaultValue); - } - - public static int parseInt(String s, int defaultValue) { - return NumberUtils.toInt(s, defaultValue); - } - - public static float parseFloat(String s, float defaultValue) { - return NumberUtils.toFloat(s, defaultValue); - } - - /** - * Converts bytes to long on input. - */ - public static long bytesToLong(byte b[]) { - return bytesToLong(b, 0); - } - - public static long bytesToLong(byte b[], int pos) { - return ByteBuffer.wrap(b, pos, 8).getLong(); - } - - /** - * Converts a byte array to a hex readable string. - **/ - public static String bytesToString(byte[] data, int start, int end) { - StringBuilder buf = new StringBuilder(); - if (end > data.length) { - end = data.length; - } - for (int i = start; i < end; i++) { - buf.append(" "); - buf.append(Integer.toHexString(data[i] & 0xff)); - } - return buf.toString(); - } - - protected static final long KB = 1024; - protected static final long MB = 1024 * KB; - protected static final long GB = 1024 * MB; - protected static final long TB = 1024 * GB; - - public static String toReadableSize(long bytes) { - if (bytes < KB && bytes >= 0) { - return Long.toString(bytes) + " bytes"; - } - StringBuilder builder = new StringBuilder(); - Formatter format = new Formatter(builder, Locale.getDefault()); - if (bytes < MB) { - format.format("%.2f KB", (float)bytes / (float)KB); - } else if (bytes < GB) { - format.format("%.2f MB", (float)bytes / (float)MB); - } else if (bytes < TB) { - format.format("%.2f GB", (float)bytes / (float)GB); - } else { - format.format("%.4f TB", (float)bytes / (float)TB); - } - format.close(); - return builder.toString(); - } - - /** - * Converts a string of the format 'yy-MM-dd'T'HH:mm:ss.SSS" into ms. - * - * @param str containing the interval. - * @param defaultValue value to return if str doesn't parse. If -1, throws VmopsRuntimeException - * @return interval in ms - */ - public static long parseInterval(String str, long defaultValue) { - try { - if (str == null) { - throw new ParseException("String is wrong", 0); - } - - SimpleDateFormat sdf = null; - if (str.contains("D")) { - sdf = new SimpleDateFormat("dd'D'HH'h'mm'M'ss'S'SSS'ms'"); - } else if (str.contains("h")) { - sdf = new SimpleDateFormat("HH'h'mm'M'ss'S'SSS'ms'"); - } else if (str.contains("M")) { - sdf = new SimpleDateFormat("mm'M'ss'S'SSS'ms'"); - } else if (str.contains("S")) { - sdf = new SimpleDateFormat("ss'S'SSS'ms'"); - } else if (str.contains("ms")) { - sdf = new SimpleDateFormat("SSS'ms'"); - } - if (sdf == null) { - throw new ParseException("String is wrong", 0); - } - - Date date = sdf.parse(str); - return date.getTime(); - } catch (ParseException e) { - if (defaultValue != -1) { - return defaultValue; - } else { - throw new CloudRuntimeException("Unable to parse: " + str, e); - } - } - } - - public static int hash(long value) { - return (int)(value ^ (value >>> 32)); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/Pair.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/Pair.java b/utils/src/com/cloud/utils/Pair.java deleted file mode 100644 index 73d3562..0000000 --- a/utils/src/com/cloud/utils/Pair.java +++ /dev/null @@ -1,87 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.io.Serializable; - -public class Pair<T, U> implements Serializable { - private static final long serialVersionUID = 2L; - T t; - U u; - - protected Pair() { - - } - - public Pair(T t, U u) { - this.t = t; - this.u = u; - } - - public T first() { - return t; - } - - public U second() { - return u; - } - - public U second(U value) { - u = value; - return u; - } - - public T first(T value) { - t = value; - return t; - } - - public void set(T t, U u) { - this.t = t; - this.u = u; - } - - @Override - // Note: This means any two pairs with null for both values will match each - // other but what can I do? This is due to stupid type erasure. - public - int hashCode() { - return (t != null ? t.hashCode() : 0) | (u != null ? u.hashCode() : 0); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Pair)) { - return false; - } - Pair<?, ?> that = (Pair<?, ?>)obj; - return (t != null ? t.equals(that.t) : that.t == null) && (u != null ? u.equals(that.u) : that.u == null); - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder("P["); - b.append((t != null) ? t.toString() : "null"); - b.append(":"); - b.append((u != null) ? u.toString() : "null"); - b.append("]"); - return b.toString(); - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/PasswordGenerator.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/PasswordGenerator.java b/utils/src/com/cloud/utils/PasswordGenerator.java deleted file mode 100644 index 0d79143..0000000 --- a/utils/src/com/cloud/utils/PasswordGenerator.java +++ /dev/null @@ -1,90 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -import java.security.SecureRandom; -import java.util.Random; - -/** - * Generate random passwords - * - */ -public class PasswordGenerator { - //Leave out visually confusing l,L,1,o,O,0 - static private char[] lowerCase = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; - static private char[] upperCase = new char[] {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; - static private char[] numeric = new char[] {'2', '3', '4', '5', '6', '7', '8', '9'}; - - static private char[] alphaNumeric = new char[] {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', - 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '2', '3', '4', '5', '6', '7', '8', '9'}; - - static private int minLength = 3; - - public static String generateRandomPassword(int num) { - Random r = new SecureRandom(); - StringBuilder password = new StringBuilder(); - - //Guard for num < minLength - if (num < minLength) { - //Add alphanumeric chars at random - for (int i = 0; i < minLength; i++) { - password.append(generateAlphaNumeric(r)); - } - } else { - // Generate random 3-character string with a lowercase character, - // uppercase character, and a digit - password.append(generateLowercaseChar(r)).append(generateUppercaseChar(r)).append(generateDigit(r)); - - // Generate a random n-character string with only lowercase - // characters - for (int i = 0; i < num - 3; i++) { - password.append(generateLowercaseChar(r)); - } - } - - return password.toString(); - } - - private static char generateLowercaseChar(Random r) { - return lowerCase[r.nextInt(lowerCase.length)]; - } - - private static char generateDigit(Random r) { - return numeric[r.nextInt(numeric.length)]; - } - - private static char generateUppercaseChar(Random r) { - return upperCase[r.nextInt(upperCase.length)]; - } - - private static char generateAlphaNumeric(Random r) { - return alphaNumeric[r.nextInt(alphaNumeric.length)]; - } - - public static String generatePresharedKey(int numChars) { - Random r = new SecureRandom(); - StringBuilder psk = new StringBuilder(); - for (int i = 0; i < numChars; i++) { - psk.append(generateAlphaNumeric(r)); - } - return psk.toString(); - - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83fd8f60/utils/src/com/cloud/utils/Predicate.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/Predicate.java b/utils/src/com/cloud/utils/Predicate.java deleted file mode 100644 index 6079d16..0000000 --- a/utils/src/com/cloud/utils/Predicate.java +++ /dev/null @@ -1,24 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.utils; - -public interface Predicate { - boolean checkCondition(); -}