├── tests ├── osgi-tests │ └── src │ │ └── test │ │ ├── resources │ │ ├── deployment │ │ │ ├── README.txt │ │ │ └── text-files │ │ │ │ └── sample1.txt │ │ ├── testng.xml │ │ └── conf │ │ │ └── deployment.yaml │ │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── deployment │ │ └── engine │ │ └── osgi │ │ ├── CustomLifecycleListener.java │ │ ├── CustomDeployer.java │ │ └── CarbonDeploymentEngineOSGiTest.java ├── pom.xml └── test-distribution │ ├── carbon-home │ └── conf │ │ └── deployment.yaml │ └── src │ └── assembly │ └── bin.xml ├── components ├── org.wso2.carbon.deployment.engine │ ├── src │ │ ├── test │ │ │ ├── resources │ │ │ │ ├── carbon-repo │ │ │ │ │ ├── conf │ │ │ │ │ │ └── sample1.txt │ │ │ │ │ └── text-files │ │ │ │ │ │ └── sample1.txt │ │ │ │ ├── deployment │ │ │ │ │ ├── conf │ │ │ │ │ │ └── sample2.txt │ │ │ │ │ └── text-files │ │ │ │ │ │ └── sample2.txt │ │ │ │ ├── sample.txt │ │ │ │ ├── jndi.properties │ │ │ │ ├── testng.xml │ │ │ │ └── yaml │ │ │ │ │ └── conf │ │ │ │ │ ├── deployment.yaml │ │ │ │ │ ├── deployment.activemq.yaml │ │ │ │ │ └── deployment.andes.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── wso2 │ │ │ │ └── carbon │ │ │ │ └── deployment │ │ │ │ └── engine │ │ │ │ ├── listeners │ │ │ │ └── CustomLifecycleListener.java │ │ │ │ ├── exception │ │ │ │ ├── DeploymentEngineExceptionTest.java │ │ │ │ └── DeployerRegistrationExceptionTest.java │ │ │ │ ├── UtilsTest.java │ │ │ │ ├── BaseTest.java │ │ │ │ ├── ArtifactTest.java │ │ │ │ ├── deployers │ │ │ │ ├── FaultyDeployer2.java │ │ │ │ ├── FaultyDeployer1.java │ │ │ │ └── CustomDeployer.java │ │ │ │ ├── DeployerTest.java │ │ │ │ ├── service │ │ │ │ └── CustomDeploymentService.java │ │ │ │ └── DeploymentServiceTest.java │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── wso2 │ │ │ └── carbon │ │ │ └── deployment │ │ │ └── engine │ │ │ ├── package-info.java │ │ │ ├── config │ │ │ ├── package-info.java │ │ │ ├── DeploymentModeEnum.java │ │ │ ├── DeploymentConfiguration.java │ │ │ └── DeploymentNotifierConfig.java │ │ │ ├── LifecycleListener.java │ │ │ ├── ArtifactType.java │ │ │ ├── Constants.java │ │ │ ├── exception │ │ │ ├── DeploymentEngineException.java │ │ │ ├── CarbonDeploymentException.java │ │ │ ├── DeployerRegistrationException.java │ │ │ └── DeploymentListenerRegistrationException.java │ │ │ ├── internal │ │ │ ├── SchedulerTask.java │ │ │ ├── OSGiServiceHolder.java │ │ │ ├── Utils.java │ │ │ ├── DataHolder.java │ │ │ └── CarbonDeploymentService.java │ │ │ ├── Deployer.java │ │ │ ├── LifecycleEvent.java │ │ │ ├── DeploymentService.java │ │ │ └── Artifact.java │ └── pom.xml └── org.wso2.carbon.deployment.notifier │ └── src │ ├── test │ ├── resources │ │ ├── carbon-repo │ │ │ ├── conf │ │ │ │ └── sample1.txt │ │ │ └── text-files │ │ │ │ └── sample1.txt │ │ ├── deployment │ │ │ ├── conf │ │ │ │ └── sample2.txt │ │ │ └── text-files │ │ │ │ └── sample2.txt │ │ ├── sample.txt │ │ ├── jndi.properties │ │ ├── testng.xml │ │ └── yaml │ │ │ └── conf │ │ │ ├── deployment.yaml │ │ │ ├── deployment.activemq.yaml │ │ │ └── deployment.andes.yaml │ └── java │ │ └── org │ │ └── wso2 │ │ └── carbon │ │ └── deployment │ │ └── notifier │ │ ├── listeners │ │ └── CustomLifecycleListener.java │ │ ├── BaseTest.java │ │ ├── DeployerTest.java │ │ ├── service │ │ └── CustomDeploymentService.java │ │ ├── deployers │ │ ├── FaultyDeployer2.java │ │ ├── FaultyDeployer1.java │ │ └── CustomDeployer.java │ │ └── DeploymentServiceTest.java │ └── main │ └── java │ └── org │ └── wso2 │ └── carbon │ └── deployment │ └── notifier │ ├── package-info.java │ ├── DeploymentNotifierException.java │ ├── Constants.java │ └── internal │ ├── DataHolder.java │ ├── DeploymentNotificationMessage.java │ └── DeploymentNotifierListenerComponent.java ├── .gitignore ├── features ├── org.wso2.carbon.deployment.engine.feature │ ├── resources │ │ ├── README.txt │ │ └── p2.inf │ └── pom.xml └── org.wso2.carbon.deployment.notifier.feature │ └── pom.xml ├── issue_template.md ├── pull_request_template.md └── README.md /tests/osgi-tests/src/test/resources/deployment/README.txt: -------------------------------------------------------------------------------- 1 | Empty file -------------------------------------------------------------------------------- /tests/osgi-tests/src/test/resources/deployment/text-files/sample1.txt: -------------------------------------------------------------------------------- 1 | This is sample1 text file -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/resources/carbon-repo/conf/sample1.txt: -------------------------------------------------------------------------------- 1 | This is sample1 text file -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/resources/deployment/conf/sample2.txt: -------------------------------------------------------------------------------- 1 | This is sample2 text file -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/resources/carbon-repo/text-files/sample1.txt: -------------------------------------------------------------------------------- 1 | This is sample1 text file -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/resources/deployment/text-files/sample2.txt: -------------------------------------------------------------------------------- 1 | This is sample2 text file -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/resources/carbon-repo/conf/sample1.txt: -------------------------------------------------------------------------------- 1 | This is sample1 text file -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/resources/deployment/conf/sample2.txt: -------------------------------------------------------------------------------- 1 | This is sample2 text file 2 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/resources/carbon-repo/text-files/sample1.txt: -------------------------------------------------------------------------------- 1 | This is sample1 text file -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/resources/sample.txt: -------------------------------------------------------------------------------- 1 | Test resources for org.wso2.carbon.utils.FileUtils.java -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/resources/deployment/text-files/sample2.txt: -------------------------------------------------------------------------------- 1 | This is sample2 text file 2 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/resources/sample.txt: -------------------------------------------------------------------------------- 1 | Test resources for org.wso2.carbon.utils.FileUtils.java -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | target 3 | .classpath 4 | .settings 5 | .project 6 | *.iml 7 | *.iws 8 | *.ipr 9 | .idea 10 | .DS_Store 11 | 12 | -------------------------------------------------------------------------------- /features/org.wso2.carbon.deployment.engine.feature/resources/README.txt: -------------------------------------------------------------------------------- 1 | This directory can be used to deploy all kind of deployable artifacts in Carbon. 2 | The 'server' directory is the place to deploy all your artifacts. 3 | 4 | You can have any directories inside the 'server' folder, based on the registered deployer it belongs 5 | 6 | Eg : 7 | dataservices - for data service deployment 8 | webapps - Directory used for hosting webapps -------------------------------------------------------------------------------- /features/org.wso2.carbon.deployment.engine.feature/resources/p2.inf: -------------------------------------------------------------------------------- 1 | metaRequirements.0.namespace = org.eclipse.equinox.p2.iu 2 | metaRequirements.0.name = org.wso2.carbon.extensions.touchpoint 3 | metaRequirements.0.optional=true 4 | instructions.configure = \ 5 | org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment); \ 6 | org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../lib/features/org.wso2.carbon.deployment.engine_${feature.version}/README.txt,target:${installFolder}/../../deployment/README.txt,overwrite:true);\ 7 | org.wso2.carbon.extensions.touchpoint.mkdir(path:${installFolder}/../{runtime}/deployment); \ -------------------------------------------------------------------------------- /tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | org.wso2.carbon.deployment.parent 5 | org.wso2.carbon.deployment 6 | 5.1.8-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | tests 11 | pom 12 | WSO2 Carbon Deployment - Tests Parent 13 | 14 | 15 | test-distribution 16 | osgi-tests 17 | 18 | 19 | -------------------------------------------------------------------------------- /issue_template.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | 4 | **Suggested Labels:** 5 | 6 | 7 | **Suggested Assignees:** 8 | 9 | 10 | **Affected Product Version:** 11 | 12 | **OS, DB, other environment details and versions:** 13 | 14 | **Steps to reproduce:** 15 | 16 | 17 | **Related Issues:** 18 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * package-info class. 19 | * 20 | * @since 5.0.0 21 | */ 22 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://wso2.org/carbon/xmlns/v5.0.0", 23 | elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 24 | package org.wso2.carbon.deployment.engine; 25 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/main/java/org/wso2/carbon/deployment/notifier/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * package-info class. 19 | * 20 | * @since 5.0.0 21 | */ 22 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://wso2.org/carbon/xmlns/v5.0.0", 23 | elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 24 | package org.wso2.carbon.deployment.notifier; 25 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/config/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * package-info class. 18 | * 19 | * @since 5.0.0 20 | */ 21 | @javax.xml.bind.annotation.XmlSchema(namespace = "http://wso2.org/carbon/xmlns/v5.0.0", 22 | elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 23 | package org.wso2.carbon.deployment.engine.config; 24 | -------------------------------------------------------------------------------- /tests/osgi-tests/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/resources/jndi.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2011, WSO2 Inc. (http://wso2.com) All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # register some connection factories 18 | # connectionfactory.[jndiname] = [ConnectionURL] 19 | connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672' 20 | 21 | # register some queues in JNDI using the form 22 | # queue.[jndiName] = [physicalName] 23 | queue.MyQueue = example.MyQueue 24 | 25 | # register some topics in JNDI using the form 26 | # topic.[jndiName] = [physicalName] 27 | topic.topic0 = topic0 28 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/resources/jndi.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2011, WSO2 Inc. (http://wso2.com) All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # register some connection factories 18 | # connectionfactory.[jndiname] = [ConnectionURL] 19 | connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672' 20 | 21 | # register some queues in JNDI using the form 22 | # queue.[jndiName] = [physicalName] 23 | queue.MyQueue = example.MyQueue 24 | 25 | # register some topics in JNDI using the form 26 | # topic.[jndiName] = [physicalName] 27 | topic.topic0 = topic0 28 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/config/DeploymentModeEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.config; 17 | 18 | import javax.xml.bind.annotation.XmlEnum; 19 | 20 | /** 21 | * JAXB mapping for Deployment Mode Enum. 22 | * 23 | * @since 5.0.0 24 | */ 25 | @XmlEnum 26 | public enum DeploymentModeEnum { 27 | triggered, 28 | scheduled; 29 | 30 | public static DeploymentModeEnum fromValue(String v) { 31 | return valueOf(v); 32 | } 33 | 34 | public String value() { 35 | return name(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/resources/testng.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/LifecycleListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.deployment.engine; 19 | 20 | /** 21 | * The interface for lifecycle listeners for artifact deployment events. 22 | * 23 | * To listen on artifact deployment events, developers should implement this 24 | * interface, and register it as an OSGi service 25 | * 26 | * @since 5.1.0 27 | */ 28 | public interface LifecycleListener { 29 | 30 | /** 31 | * Listen in on artifact deployment events and perform an action. 32 | * 33 | * @param event The lifecycle event. The Artifact object and 34 | * the currently triggered lifecycle event is stored 35 | * in this. 36 | */ 37 | void lifecycleEvent(LifecycleEvent event); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tests/test-distribution/carbon-home/conf/deployment.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the \"License\"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an \"AS IS\" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Carbon Configuration Parameters 16 | wso2.carbon: 17 | # value to uniquely identify a server 18 | id: carbon-kernel 19 | # server name 20 | name: WSO2 Carbon Kernel 21 | # ports used by this server 22 | ports: 23 | # port offset 24 | offset: 0 25 | 26 | wso2.securevault: 27 | secretRepository: 28 | type: org.wso2.carbon.secvault.repository.DefaultSecretRepository 29 | parameters: 30 | privateKeyAlias: wso2carbon 31 | keystoreLocation: ${sys:carbon.home}/resources/security/securevault.jks 32 | secretPropertiesFile: ${sys:carbon.home}/conf/${sys:wso2.runtime}/secrets.properties 33 | masterKeyReader: 34 | type: org.wso2.carbon.secvault.reader.DefaultMasterKeyReader 35 | parameters: 36 | masterKeyReaderFile: ${sys:carbon.home}/conf/${sys:wso2.runtime}/master-keys.yaml -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/ArtifactType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine; 17 | 18 | /** 19 | * This class represent the artifact type of an artifact. 20 | * 21 | * @since 5.0.0 22 | * @param Artifact type 23 | */ 24 | public class ArtifactType { 25 | private T type; 26 | 27 | /** 28 | * 29 | * @param type the artifact type. If the type is 30 | * represented by a class other than String, 31 | * then make sure to over-ride #toString 32 | */ 33 | public ArtifactType(T type) { 34 | this.type = type; 35 | } 36 | 37 | public T get() { 38 | return type; 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | return type.hashCode(); 44 | } 45 | 46 | @Override 47 | public boolean equals(Object other) { 48 | return other != null && this.getClass() == other.getClass() && this.type.equals(((ArtifactType) other).get()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.deployment.engine; 20 | 21 | /** 22 | * Constants for deployment framework. 23 | * 24 | * @since 5.1.0 25 | * 26 | */ 27 | public final class Constants { 28 | 29 | public static final String DEPLOYMENT_NOTIFIER_CONNECTION_FACTORY_JNDI_NAME = "TopicConnectionFactory"; 30 | 31 | public static final String DEPLOYMENT_NOTIFIER_CONNECTION_STRING = "connectionfactory.TopicConnectionFactory"; 32 | 33 | public static final String DEPLOYMENT_NOTIFIER_TOPIC_JNDI_NAME = "deploymentTopic"; 34 | 35 | public static final String DESTINATION_TYPE_QUEUE = "queue"; 36 | 37 | public static final String DESTINATION_TYPE_TOPIC = "topic"; 38 | 39 | public static final String QUEUE_PREFIX = "queue."; 40 | 41 | public static final String TOPIC_PREFIX = "topic."; 42 | 43 | public static final String JMS_USERNAME_PROPERTY = "jmsUsername"; 44 | 45 | public static final String JMS_PASSWORD_PROPERTY = "jmsPassword"; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /tests/osgi-tests/src/test/java/org/wso2/carbon/deployment/engine/osgi/CustomLifecycleListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) $today.year, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.deployment.engine.osgi; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | import org.wso2.carbon.deployment.engine.Artifact; 23 | import org.wso2.carbon.deployment.engine.LifecycleEvent; 24 | import org.wso2.carbon.deployment.engine.LifecycleListener; 25 | 26 | /** 27 | * Custom lifecycle listener for testing. 28 | */ 29 | public class CustomLifecycleListener implements LifecycleListener { 30 | 31 | private static final Logger logger = LoggerFactory.getLogger(CustomLifecycleListener.class); 32 | 33 | @Override 34 | public void lifecycleEvent(LifecycleEvent event) { 35 | Artifact artifact = event.getArtifact(); 36 | String artifactName = artifact.getName(); 37 | 38 | LifecycleEvent.RESULT deploymentResult = event.getDeploymentResult(); 39 | 40 | logger.info("{} event triggered for artifact: {}, with current deployment result: {} ", event.getState(), 41 | artifactName, deploymentResult); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/exception/DeploymentEngineException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.exception; 17 | 18 | /** 19 | * Represents the Deployment Engine related Exception. 20 | * 21 | * @since 5.0.0 22 | */ 23 | public class DeploymentEngineException extends Exception { 24 | 25 | /** 26 | * This will construct the DeploymentEngineException with the detailed exception message. 27 | * 28 | * @param message the detailed exception message to be included with DeploymentEngineException 29 | */ 30 | public DeploymentEngineException(String message) { 31 | super(message); 32 | } 33 | 34 | /** 35 | * This will construct a new DeploymentEngineException with the specified detail message and 36 | * cause. 37 | * 38 | * @param message the exception message to be included with DeploymentEngineException 39 | * @param cause the cause exception to be included with DeploymentEngineException 40 | */ 41 | public DeploymentEngineException(String message, Exception cause) { 42 | super(message, cause); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/listeners/CustomLifecycleListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) $today.year, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.deployment.engine.listeners; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | import org.wso2.carbon.deployment.engine.Artifact; 23 | import org.wso2.carbon.deployment.engine.LifecycleEvent; 24 | import org.wso2.carbon.deployment.engine.LifecycleListener; 25 | 26 | /** 27 | * Custom lifecycle listener for testing. 28 | */ 29 | public class CustomLifecycleListener implements LifecycleListener { 30 | 31 | private static final Logger logger = LoggerFactory.getLogger(CustomLifecycleListener.class); 32 | 33 | @Override 34 | public void lifecycleEvent(LifecycleEvent event) { 35 | Artifact artifact = event.getArtifact(); 36 | String artifactName = artifact.getName(); 37 | 38 | LifecycleEvent.RESULT deploymentResult = event.getDeploymentResult(); 39 | 40 | logger.info("{} event triggered for artifact: {}, with current deployment result: {} ", event.getState(), 41 | artifactName, deploymentResult); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/java/org/wso2/carbon/deployment/notifier/listeners/CustomLifecycleListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) $today.year, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.deployment.notifier.listeners; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | import org.wso2.carbon.deployment.engine.Artifact; 23 | import org.wso2.carbon.deployment.engine.LifecycleEvent; 24 | import org.wso2.carbon.deployment.engine.LifecycleListener; 25 | 26 | /** 27 | * Custom lifecycle listener for testing. 28 | */ 29 | public class CustomLifecycleListener implements LifecycleListener { 30 | 31 | private static final Logger logger = LoggerFactory.getLogger(CustomLifecycleListener.class); 32 | 33 | @Override 34 | public void lifecycleEvent(LifecycleEvent event) { 35 | Artifact artifact = event.getArtifact(); 36 | String artifactName = artifact.getName(); 37 | 38 | LifecycleEvent.RESULT deploymentResult = event.getDeploymentResult(); 39 | 40 | logger.info("{} event triggered for artifact: {}, with current deployment result: {} ", event.getState(), 41 | artifactName, deploymentResult); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/exception/CarbonDeploymentException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.exception; 17 | 18 | /** 19 | * The exception class for all deployment related the exception that 20 | * can be thrown from CarbonDeployementEngine. 21 | * 22 | * @since 5.0.0 23 | */ 24 | public class CarbonDeploymentException extends Exception { 25 | /** 26 | * This will construct the CarbonDeploymentException with the detailed exception message. 27 | * @param message the detailed exception message to be included with CarbonDeploymentException 28 | */ 29 | public CarbonDeploymentException(String message) { 30 | super(message); 31 | } 32 | 33 | /** 34 | * This will construct a new CarbonDeploymentException with the specified detail message and 35 | * cause. 36 | * 37 | * @param message the exception message to be included with CarbonDeploymentException 38 | * @param cause the cause exception to be included with CarbonDeploymentException 39 | */ 40 | public CarbonDeploymentException(String message, Exception cause) { 41 | super(message, cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/exception/DeploymentEngineExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.exception; 17 | 18 | import org.testng.Assert; 19 | import org.testng.annotations.Test; 20 | 21 | /** 22 | * Unit test class for DeploymentEngineException. 23 | * 24 | * @since 5.0.0 25 | */ 26 | public class DeploymentEngineExceptionTest { 27 | 28 | @Test 29 | public void testDeploymentEngineException() { 30 | try { 31 | throw new DeploymentEngineException("sample exception"); 32 | } catch (DeploymentEngineException e) { 33 | String exceptionMessage = "sample exception"; 34 | Assert.assertEquals(exceptionMessage, e.getMessage()); 35 | } 36 | } 37 | 38 | @Test 39 | public void testDeploymentEngineExceptionWithThrowable() { 40 | try { 41 | RuntimeException exception = new RuntimeException(); 42 | throw new DeploymentEngineException("sample exception", exception); 43 | } catch (DeploymentEngineException e) { 44 | Assert.assertTrue(e.getCause() instanceof RuntimeException); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/internal/SchedulerTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.internal; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | /** 22 | * The Scheduler Task which gets called periodically by the executor service and 23 | * calls the repository scanner internally. 24 | * 25 | * @since 5.0.0 26 | */ 27 | public class SchedulerTask implements Runnable { 28 | private static final Logger logger = LoggerFactory.getLogger(SchedulerTask.class); 29 | 30 | private RepositoryScanner repositoryScanner; 31 | 32 | /** 33 | * This will construct the SchedulerTask with the given RepositoryScanner instance. 34 | * 35 | * @param repositoryScanner the repositoryScanner instance to be used with each task run 36 | */ 37 | public SchedulerTask(RepositoryScanner repositoryScanner) { 38 | this.repositoryScanner = repositoryScanner; 39 | } 40 | 41 | public void run() { 42 | try { 43 | repositoryScanner.scan(); 44 | } catch (Throwable e) { 45 | logger.error("Error occurred while scanning deployment repository", e); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/exception/DeployerRegistrationExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.exception; 17 | 18 | import org.testng.Assert; 19 | import org.testng.annotations.Test; 20 | 21 | /** 22 | * Unit test class for DeployerRegistrationExceptionTest. 23 | * 24 | * @since 5.0.0 25 | */ 26 | public class DeployerRegistrationExceptionTest { 27 | 28 | @Test 29 | public void testDeployerRegistrationException() { 30 | try { 31 | throw new DeployerRegistrationException("sample exception"); 32 | } catch (DeployerRegistrationException e) { 33 | String exceptionMessage = "sample exception"; 34 | Assert.assertEquals(exceptionMessage, e.getMessage()); 35 | } 36 | } 37 | 38 | @Test 39 | public void testDeployerRegistrationExceptionWithThrowable() { 40 | try { 41 | RuntimeException exception = new RuntimeException(); 42 | throw new DeployerRegistrationException("sample exception", exception); 43 | } catch (DeployerRegistrationException e) { 44 | Assert.assertTrue(e.getCause() instanceof RuntimeException); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/test-distribution/src/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | true 18 | wso2carbon-deployment-test-${project.version} 19 | carbon-deployment 20 | 21 | zip 22 | 23 | 24 | 25 | 26 | target/wso2carbon-deployment-${carbon.deployment.version} 27 | . 28 | 29 | README.txt 30 | LICENSE.txt 31 | INSTALL.txt 32 | release-notes.html 33 | **/*.ipr 34 | **/*.iwr 35 | **/*.eclipse 36 | 37 | 38 | 39 | 40 | 41 | carbon-home/conf/deployment.yaml 42 | conf/default/ 43 | 644 44 | true 45 | 46 | 47 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/main/java/org/wso2/carbon/deployment/notifier/DeploymentNotifierException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.deployment.notifier; 19 | 20 | /** 21 | * The exception class for all deployment notifier related the exception that 22 | * can be thrown from deployment notifier. 23 | * 24 | * @since 5.0.0 25 | */ 26 | public class DeploymentNotifierException extends RuntimeException { 27 | /** 28 | * This will construct the DeploymentNotifierException with the detailed exception message. 29 | * @param message the detailed exception message to be included with DeploymentNotifierException 30 | */ 31 | public DeploymentNotifierException(String message) { 32 | super(message); 33 | } 34 | 35 | /** 36 | * This will construct a new DeploymentNotifierException with the specified detail message and 37 | * cause. 38 | * 39 | * @param message the exception message to be included with DeploymentNotifierException 40 | * @param cause the cause exception to be included with DeploymentNotifierException 41 | */ 42 | public DeploymentNotifierException(String message, Exception cause) { 43 | super(message, cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/exception/DeployerRegistrationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.exception; 17 | 18 | /** 19 | * The exception class for all deployer registration, un-registration related the exceptions that 20 | * can be thrown from CarbonDeployementEngine. 21 | * 22 | * @since 5.0.0 23 | */ 24 | 25 | public class DeployerRegistrationException extends Exception { 26 | /** 27 | * This will construct the DeployerRegistrationException with the detailed exception message. 28 | * 29 | * @param message the detailed exception message to be included with DeployerRegistrationException 30 | */ 31 | public DeployerRegistrationException(String message) { 32 | super(message); 33 | } 34 | 35 | /** 36 | * This will construct a new DeployerRegistrationException with the specified detail message and 37 | * cause. 38 | * 39 | * @param message the exception message to be included with DeployerRegistrationException 40 | * @param cause the cause exception to be included with DeployerRegistrationException 41 | */ 42 | public DeployerRegistrationException(String message, Exception cause) { 43 | super(message, cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/exception/DeploymentListenerRegistrationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.exception; 17 | 18 | /** 19 | * The exception class for all deployer listener registration, and un-registration related exceptions that 20 | * can be thrown from CarbonDeploymentEngine. 21 | * 22 | * @since 5.0.0 23 | */ 24 | 25 | public class DeploymentListenerRegistrationException extends Exception { 26 | /** 27 | * This will construct the DeploymentListenerRegistrationException with the detailed exception message. 28 | * 29 | * @param message the detailed exception message to be included with DeploymentListenerRegistrationException 30 | */ 31 | public DeploymentListenerRegistrationException(String message) { 32 | super(message); 33 | } 34 | 35 | /** 36 | * This will construct a new DeploymentListenerRegistrationException with the specified detail message and 37 | * cause. 38 | * 39 | * @param message the exception message to be included with DeploymentListenerRegistrationException 40 | * @param cause the cause exception to be included with DeploymentListenerRegistrationException 41 | */ 42 | public DeploymentListenerRegistrationException(String message, Exception cause) { 43 | super(message, cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/internal/OSGiServiceHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.internal; 17 | 18 | /** 19 | * A singleton data holder pattern class for holding OSGi related service instances that are used within the scope 20 | * of this bundle. This class is internal to this bundle only. 21 | * 22 | * @since 5.0.0 23 | */ 24 | public class OSGiServiceHolder { 25 | private static OSGiServiceHolder instance = new OSGiServiceHolder(); 26 | 27 | private DeploymentEngine carbonDeploymentEngine; 28 | 29 | /** 30 | * This method will return the singleton instance of this holder. 31 | * 32 | * @return OSGiServiceHolder singleton instance 33 | */ 34 | public static OSGiServiceHolder getInstance() { 35 | return instance; 36 | } 37 | 38 | /** 39 | * This method used within this bundle scope to get the currently held carbonDeploymentEngine service instance 40 | * within this holder. 41 | * 42 | * @return this will return the carbonDeploymentEngine service instance. 43 | */ 44 | public DeploymentEngine getCarbonDeploymentEngine() { 45 | return carbonDeploymentEngine; 46 | } 47 | 48 | /** 49 | * This method is called by the relevant service component that acquires the carbonDeploymentEngine service 50 | * instance and will be stored for future look-ups. 51 | * 52 | * @param carbonDeploymentEngine the carbonDeploymentEngine to be stored by this holder 53 | */ 54 | public void setCarbonDeploymentEngine(DeploymentEngine carbonDeploymentEngine) { 55 | this.carbonDeploymentEngine = carbonDeploymentEngine; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/main/java/org/wso2/carbon/deployment/notifier/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | 19 | package org.wso2.carbon.deployment.notifier; 20 | 21 | /** 22 | * Constants for deployment notifier. 23 | * 24 | * @since 5.1.0 25 | * 26 | */ 27 | public final class Constants { 28 | 29 | public static final String DESTINATION_TYPE_TOPIC = "topic"; 30 | 31 | public static final String QUEUE_PREFIX = "queue."; 32 | 33 | public static final String TOPIC_PREFIX = "topic."; 34 | 35 | /** 36 | * The Parameter name indicating the JMS connection factory JNDI name. 37 | */ 38 | public static final String PARAM_CONFAC_JNDI_NAME = "connectionFactoryJNDIName"; 39 | 40 | /** 41 | * The parameter indicating the JMS API specification to be used. 42 | * if this is "1.1" the JMS 1.1 API would be used, else the JMS 1.0.2B 43 | */ 44 | public static final String PARAM_JMS_SPEC_VER = "jmsSpecVersion"; 45 | 46 | /** 47 | * The username to use when obtaining a JMS Connection. 48 | */ 49 | public static final String PARAM_JMS_USERNAME = "jmsUserName"; 50 | /** 51 | * The password to use when obtaining a JMS Connection. 52 | */ 53 | public static final String PARAM_JMS_PASSWORD = "jmsPassword"; 54 | 55 | /** 56 | * The Service level Parameter name indicating the JMS destination for requests of a service. 57 | */ 58 | public static final String PARAM_DESTINATION = "destinationJNDIName"; 59 | 60 | /** 61 | * The Service level Parameter name indicating the destination type for requests. 62 | */ 63 | public static final String PARAM_DEST_TYPE = "destinationType"; 64 | 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /tests/osgi-tests/src/test/resources/conf/deployment.yaml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | # Deployment Engine related configurations 18 | #deployment: 19 | 20 | # Currently there can be two modes 21 | # 1. Scheduled Mode - (enable below property to "scheduled") - where the task runs periodically and trigger deployment 22 | # 2. Triggered Mode - (enable below property to "triggered") - the deployment has to be triggered externally, 23 | # eg : in a worker node we don't need the task to run, but rather when we receive a 24 | # cluster msg, the deployment has to be triggered manually 25 | # Deployment configuration parameters 26 | wso2.artifact.deployment: 27 | # deployment mode 28 | mode: scheduled 29 | # repository location 30 | repositoryLocation: ${sys:carbon.home}/deployment/ 31 | # Scheduler update interval 32 | updateInterval: 15 33 | # Deployment notifier configuration parameters 34 | deploymentNotifier: 35 | # JMS publishing enabled 36 | jmsPublishingEnabled: false 37 | # Desitination JNDI name 38 | destinationJNDIName: topic0 39 | # Destination type 40 | destinationType: topic 41 | # Java naming factory initial 42 | javaNamingFactoryInitial: org.apache.activemq.jndi.ActiveMQInitialContextFactory 43 | # Java naming provider URL 44 | javaNamingProviderURL: vm://carbon?create=false 45 | # JMS user name 46 | #jmsUsername: admin 47 | # JMS password 48 | #jmsPassword: admin 49 | # Connection factory JNDI name 50 | connectionFactoryJNDIName: TopicConnectionFactory 51 | # Static massage content 52 | staticMessageContent: {} 53 | 54 | 55 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/UtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine; 17 | 18 | import org.testng.Assert; 19 | import org.testng.annotations.Test; 20 | import org.wso2.carbon.deployment.engine.internal.Utils; 21 | 22 | import java.nio.file.Paths; 23 | 24 | /** 25 | * This class tests the functionality of Utils class. 26 | * 27 | * @since 5.0.0 28 | */ 29 | public class UtilsTest { 30 | 31 | @Test 32 | public void testResolveFileURLFailOnNoneFileURLs() { 33 | String pathURL = "http://felix.apache.org/documentation/subprojects/apache-felix-service-runtime.html"; 34 | try { 35 | Utils.resolveFileURL(pathURL, null); 36 | } catch (RuntimeException e) { 37 | Assert.assertEquals(e.getMessage(), "URLs other than file URLs are not supported."); 38 | } 39 | } 40 | 41 | @Test 42 | public void testResolveFileURLStartsWithFile() { 43 | String pathURL = "file:/home/Carbon/carbon-kernel-c5/carbon-kernel/core"; 44 | String parentUrl = "/home/Carbon/carbon-kernel-c5/carbon-kernel/core"; 45 | try { 46 | Utils.resolveFileURL(pathURL, parentUrl); 47 | } catch (RuntimeException e) { 48 | Assert.assertTrue(false); 49 | } 50 | } 51 | 52 | @Test 53 | public void testResolveFileMalformedUrl() { 54 | String pathURL = Paths.get("carbon-kernel-c5", "carbon-kernel", "core").toFile().toString(); 55 | String parentUrl = "home"; 56 | try { 57 | Utils.resolveFileURL(pathURL, parentUrl); 58 | } catch (RuntimeException e) { 59 | Assert.assertEquals(e.getMessage(), "Malformed URL : " + pathURL); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/BaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine; 17 | 18 | import java.io.File; 19 | import java.io.FileInputStream; 20 | import java.io.FileNotFoundException; 21 | import java.io.InputStream; 22 | 23 | /** 24 | * BaseTest class for deployment tests. 25 | * 26 | * @since 5.0.0 27 | */ 28 | public class BaseTest { 29 | 30 | /** 31 | * Basedir for all file I/O. 32 | */ 33 | public static String basedir; 34 | 35 | static { 36 | basedir = System.getProperty("basedir"); 37 | if (basedir == null) { 38 | basedir = new File(".").getAbsolutePath(); 39 | } 40 | } 41 | 42 | protected String testDir = "src" + File.separator + "test" + File.separator; 43 | protected String testResourceDir = testDir + "resources"; 44 | 45 | /** 46 | * @param testName 47 | */ 48 | public BaseTest(String testName) { 49 | testDir = new File(basedir, testDir).getAbsolutePath(); 50 | testResourceDir = new File(basedir, testResourceDir).getAbsolutePath(); 51 | } 52 | 53 | public File getTestResourceFile(String relativePath) { 54 | return new File(testResourceDir, relativePath); 55 | } 56 | 57 | public InputStream getTestResource(String relativePath) { 58 | File testResource = getTestResourceFile(relativePath); 59 | try { 60 | return new FileInputStream(testResource); 61 | } catch (FileNotFoundException e) { 62 | throw new IllegalStateException("The '" + testResource.getAbsolutePath() + 63 | "' file does not exist. Verify that the 'basedir' System property " + 64 | "is pointing to the root of the project", e); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/resources/yaml/conf/deployment.yaml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | # Deployment Engine related configurations 18 | #deployment: 19 | 20 | # Currently there can be two modes 21 | # 1. Scheduled Mode - (enable below property to "scheduled") - where the task runs periodically and trigger deployment 22 | # 2. Triggered Mode - (enable below property to "triggered") - the deployment has to be triggered externally, 23 | # eg : in a worker node we don't need the task to run, but rather when we receive a 24 | # cluster msg, the deployment has to be triggered manually 25 | wso2.artifact.deployment: 26 | mode: scheduled 27 | 28 | # Location of the artifact repository 29 | serverRepositoryLocation: ${sys:carbon.home}/deployment/ 30 | 31 | # Deployment update interval in seconds. This is the interval between repository listener 32 | # executions. 33 | updateInterval: 15 34 | 35 | # Notify deployment status via JMS to a topic 36 | # In a cluster, all nodes should publish the status to the same topic which may be 37 | # listened on to take deployment decisions such as reverting artifacts. 38 | # This is disabled by default. 39 | # 40 | # Specify any static message content to be published as key-value pairs 41 | # under staticMessageContent. 42 | deploymentNotifier: 43 | jmsPublishingEnabled: true 44 | javaNamingFactoryInitial: org.apache.activemq.jndi.ActiveMQInitialContextFactory 45 | javaNamingProviderURL: vm://carbon?create=false 46 | # javaNamingProviderURL: conf/jndi.properties 47 | # jmsUsername: admin 48 | # jmsPassword: admin 49 | connectionFactoryJNDIName: TopicConnectionFactory 50 | destinationJNDIName: topic0 51 | destinationType: topic 52 | staticMessageContent: 53 | # key: value 54 | 55 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/resources/yaml/conf/deployment.yaml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | # Deployment Engine related configurations 18 | #deployment: 19 | 20 | # Currently there can be two modes 21 | # 1. Scheduled Mode - (enable below property to "scheduled") - where the task runs periodically and trigger deployment 22 | # 2. Triggered Mode - (enable below property to "triggered") - the deployment has to be triggered externally, 23 | # eg : in a worker node we don't need the task to run, but rather when we receive a 24 | # cluster msg, the deployment has to be triggered manually 25 | wso2.artifact.deployment: 26 | mode: scheduled 27 | 28 | # Location of the artifact repository 29 | serverRepositoryLocation: ${sys:carbon.home}/deployment/ 30 | 31 | # Deployment update interval in seconds. This is the interval between repository listener 32 | # executions. 33 | updateInterval: 15 34 | 35 | # Notify deployment status via JMS to a topic 36 | # In a cluster, all nodes should publish the status to the same topic which may be 37 | # listened on to take deployment decisions such as reverting artifacts. 38 | # This is disabled by default. 39 | # 40 | # Specify any static message content to be published as key-value pairs 41 | # under staticMessageContent. 42 | deploymentNotifier: 43 | jmsPublishingEnabled: false 44 | javaNamingFactoryInitial: org.wso2.andes.jndi.PropertiesFileInitialContextFactory 45 | # javaNamingProviderURL: tcp://localhost:61616 46 | javaNamingProviderURL: src/test/resources/jndi.properties 47 | jmsUsername: admin 48 | jmsPassword: admin 49 | connectionFactoryJNDIName: TopicConnectionFactory 50 | destinationJNDIName: topic0 51 | destinationType: topic 52 | staticMessageContent: 53 | # key: key-value 54 | 55 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/resources/yaml/conf/deployment.activemq.yaml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | # Deployment Engine related configurations 18 | #deployment: 19 | 20 | # Currently there can be two modes 21 | # 1. Scheduled Mode - (enable below property to "scheduled") - where the task runs periodically and trigger deployment 22 | # 2. Triggered Mode - (enable below property to "triggered") - the deployment has to be triggered externally, 23 | # eg : in a worker node we don't need the task to run, but rather when we receive a 24 | # cluster msg, the deployment has to be triggered manually 25 | wso2.artifact.deployment: 26 | mode: scheduled 27 | 28 | # Location of the artifact repository 29 | serverRepositoryLocation: ${sys:carbon.home}/deployment/ 30 | 31 | # Deployment update interval in seconds. This is the interval between repository listener 32 | # executions. 33 | updateInterval: 15 34 | 35 | # Notify deployment status via JMS to a topic 36 | # In a cluster, all nodes should publish the status to the same topic which may be 37 | # listened on to take deployment decisions such as reverting artifacts. 38 | # This is disabled by default. 39 | # 40 | # Specify any static message content to be published as key-value pairs 41 | # under staticMessageContent. 42 | deploymentNotifier: 43 | jmsPublishingEnabled: true 44 | javaNamingFactoryInitial: org.apache.activemq.jndi.ActiveMQInitialContextFactory 45 | javaNamingProviderURL: tcp://localhost:61616 46 | # javaNamingProviderURL: conf/jndi.properties 47 | # jmsUsername: admin 48 | # jmsPassword: admin 49 | connectionFactoryJNDIName: TopicConnectionFactory 50 | destinationJNDIName: topic0 51 | destinationType: topic 52 | staticMessageContent: 53 | # key: value 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/resources/yaml/conf/deployment.activemq.yaml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | # Deployment Engine related configurations 18 | #deployment: 19 | 20 | # Currently there can be two modes 21 | # 1. Scheduled Mode - (enable below property to "scheduled") - where the task runs periodically and trigger deployment 22 | # 2. Triggered Mode - (enable below property to "triggered") - the deployment has to be triggered externally, 23 | # eg : in a worker node we don't need the task to run, but rather when we receive a 24 | # cluster msg, the deployment has to be triggered manually 25 | wso2.artifact.deployment: 26 | mode: scheduled 27 | 28 | # Location of the artifact repository 29 | serverRepositoryLocation: ${sys:carbon.home}/deployment/ 30 | 31 | # Deployment update interval in seconds. This is the interval between repository listener 32 | # executions. 33 | updateInterval: 15 34 | 35 | # Notify deployment status via JMS to a topic 36 | # In a cluster, all nodes should publish the status to the same topic which may be 37 | # listened on to take deployment decisions such as reverting artifacts. 38 | # This is disabled by default. 39 | # 40 | # Specify any static message content to be published as key-value pairs 41 | # under staticMessageContent. 42 | deploymentNotifier: 43 | jmsPublishingEnabled: true 44 | javaNamingFactoryInitial: org.apache.activemq.jndi.ActiveMQInitialContextFactory 45 | javaNamingProviderURL: tcp://localhost:61616 46 | # javaNamingProviderURL: conf/jndi.properties 47 | # jmsUsername: admin 48 | # jmsPassword: admin 49 | connectionFactoryJNDIName: TopicConnectionFactory 50 | destinationJNDIName: topic0 51 | destinationType: topic 52 | staticMessageContent: 53 | # key: value 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/resources/yaml/conf/deployment.andes.yaml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | # Deployment Engine related configurations 18 | #deployment: 19 | 20 | # Currently there can be two modes 21 | # 1. Scheduled Mode - (enable below property to "scheduled") - where the task runs periodically and trigger deployment 22 | # 2. Triggered Mode - (enable below property to "triggered") - the deployment has to be triggered externally, 23 | # eg : in a worker node we don't need the task to run, but rather when we receive a 24 | # cluster msg, the deployment has to be triggered manually 25 | wso2.artifact.deployment: 26 | mode: scheduled 27 | 28 | # Location of the artifact repository 29 | serverRepositoryLocation: ${sys:carbon.home}/deployment/ 30 | 31 | # Deployment update interval in seconds. This is the interval between repository listener 32 | # executions. 33 | updateInterval: 15 34 | 35 | # Notify deployment status via JMS to a topic 36 | # In a cluster, all nodes should publish the status to the same topic which may be 37 | # listened on to take deployment decisions such as reverting artifacts. 38 | # This is disabled by default. 39 | # 40 | # Specify any static message content to be published as key-value pairs 41 | # under staticMessageContent. 42 | deploymentNotifier: 43 | jmsPublishingEnabled: true 44 | javaNamingFactoryInitial: org.wso2.andes.jndi.PropertiesFileInitialContextFactory 45 | # javaNamingProviderURL: tcp://localhost:61616 46 | javaNamingProviderURL: src/test/resources/jndi.properties 47 | jmsUsername: admin 48 | jmsPassword: admin 49 | connectionFactoryJNDIName: TopicConnectionFactory 50 | destinationJNDIName: topic0 51 | destinationType: topic 52 | staticMessageContent: 53 | # key: key-value 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/resources/yaml/conf/deployment.andes.yaml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | # Deployment Engine related configurations 18 | #deployment: 19 | 20 | # Currently there can be two modes 21 | # 1. Scheduled Mode - (enable below property to "scheduled") - where the task runs periodically and trigger deployment 22 | # 2. Triggered Mode - (enable below property to "triggered") - the deployment has to be triggered externally, 23 | # eg : in a worker node we don't need the task to run, but rather when we receive a 24 | # cluster msg, the deployment has to be triggered manually 25 | wso2.artifact.deployment: 26 | mode: scheduled 27 | 28 | # Location of the artifact repository 29 | serverRepositoryLocation: ${sys:carbon.home}/deployment/ 30 | 31 | # Deployment update interval in seconds. This is the interval between repository listener 32 | # executions. 33 | updateInterval: 15 34 | 35 | # Notify deployment status via JMS to a topic 36 | # In a cluster, all nodes should publish the status to the same topic which may be 37 | # listened on to take deployment decisions such as reverting artifacts. 38 | # This is disabled by default. 39 | # 40 | # Specify any static message content to be published as key-value pairs 41 | # under staticMessageContent. 42 | deploymentNotifier: 43 | jmsPublishingEnabled: true 44 | javaNamingFactoryInitial: org.wso2.andes.jndi.PropertiesFileInitialContextFactory 45 | # javaNamingProviderURL: tcp://localhost:61616 46 | javaNamingProviderURL: src/test/resources/jndi.properties 47 | jmsUsername: admin 48 | jmsPassword: admin 49 | connectionFactoryJNDIName: TopicConnectionFactory 50 | destinationJNDIName: topic0 51 | destinationType: topic 52 | staticMessageContent: 53 | # key: key-value 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/main/java/org/wso2/carbon/deployment/notifier/internal/DataHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.notifier.internal; 17 | 18 | import org.wso2.carbon.config.provider.ConfigProvider; 19 | import org.wso2.carbon.kernel.CarbonRuntime; 20 | 21 | /** 22 | * Deployment notifier DataHolder. 23 | * 24 | * @since 5.0.0 25 | */ 26 | public class DataHolder { 27 | private static DataHolder instance = new DataHolder(); 28 | 29 | private CarbonRuntime carbonRuntime; 30 | private ConfigProvider configProvider; 31 | 32 | public static DataHolder getInstance() { 33 | return instance; 34 | } 35 | 36 | /** 37 | * This method used within this bundle (carbon.core) scope to get the currently held carbonRuntime service instance 38 | * within this holder. 39 | * 40 | * @return this will return the carbonRuntime service instance. 41 | */ 42 | public CarbonRuntime getCarbonRuntime() { 43 | return carbonRuntime; 44 | } 45 | 46 | /** 47 | * This method is called by the relevant service component that acquires the carbonRuntime service 48 | * instance and will be stored for future look-ups. 49 | * 50 | * @param carbonRuntime the carbonRuntime to be stored with this holder 51 | */ 52 | public void setCarbonRuntime(CarbonRuntime carbonRuntime) { 53 | this.carbonRuntime = carbonRuntime; 54 | } 55 | 56 | /** 57 | * This method is called to set the config provider service. 58 | * 59 | * @param configProvider the configProvider to be stored with this holder. 60 | */ 61 | public void setConfigProvider(ConfigProvider configProvider) { 62 | this.configProvider = configProvider; 63 | } 64 | 65 | /** 66 | * This method is used to get the config provider service. 67 | * 68 | * @return this will return the configProvider service instance. 69 | */ 70 | public ConfigProvider getConfigProvider() { 71 | return configProvider; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Purpose 2 | > Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc. 3 | 4 | ## Goals 5 | > Describe the solutions that this feature/fix will introduce to resolve the problems described above 6 | 7 | ## Approach 8 | > Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here. 9 | 10 | ## User stories 11 | > Summary of user stories addressed by this change> 12 | 13 | ## Release note 14 | > Brief description of the new feature or bug fix as it will appear in the release notes 15 | 16 | ## Documentation 17 | > Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact 18 | 19 | ## Training 20 | > Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable 21 | 22 | ## Certification 23 | > Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why. 24 | 25 | ## Marketing 26 | > Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable 27 | 28 | ## Automation tests 29 | - Unit tests 30 | > Code coverage information 31 | - Integration tests 32 | > Details about the test cases and coverage 33 | 34 | ## Security checks 35 | - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no 36 | - Ran FindSecurityBugs plugin and verified report? yes/no 37 | - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no 38 | 39 | ## Samples 40 | > Provide high-level details about the samples related to this feature 41 | 42 | ## Related PRs 43 | > List any other related PRs 44 | 45 | ## Migrations (if applicable) 46 | > Describe migration steps and platforms on which migration has been tested 47 | 48 | ## Test environment 49 | > List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested 50 | 51 | ## Learning 52 | > Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem. -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/config/DeploymentConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.config; 17 | 18 | import org.wso2.carbon.config.ConfigurationUtils; 19 | import org.wso2.carbon.config.annotation.Configuration; 20 | import org.wso2.carbon.config.annotation.Element; 21 | import org.wso2.carbon.config.annotation.Ignore; 22 | 23 | /** 24 | * DeploymentConfiguration class holds static configuration parameters specified in the deployment.yml file. 25 | * 26 | * @since 5.1.0 27 | */ 28 | @Configuration(namespace = "wso2.artifact.deployment", description = "Deployment configuration parameters") 29 | public class DeploymentConfiguration { 30 | 31 | @Element(description = "deployment mode") 32 | private DeploymentModeEnum mode = DeploymentModeEnum.scheduled; 33 | 34 | @Element(description = "server repository location") 35 | private String serverRepositoryLocation = "${carbon.home}/deployment/"; 36 | 37 | @Ignore 38 | private String runtimeRepositoryLocation = "${wso2.runtime.path}/deployment/"; 39 | 40 | @Element(description = "Scheduler update interval") 41 | private int updateInterval = 15; 42 | 43 | @Element(description = "Deployment notifier config") 44 | private DeploymentNotifierConfig deploymentNotifier = new DeploymentNotifierConfig(); 45 | 46 | public DeploymentConfiguration() { 47 | serverRepositoryLocation = ConfigurationUtils.substituteVariables(serverRepositoryLocation); 48 | runtimeRepositoryLocation = ConfigurationUtils.substituteVariables(runtimeRepositoryLocation); 49 | } 50 | 51 | public DeploymentModeEnum getMode() { 52 | return mode; 53 | } 54 | 55 | public String getServerRepositoryLocation() { 56 | return serverRepositoryLocation; 57 | } 58 | 59 | public String getRuntimeRepositoryLocation() { 60 | return runtimeRepositoryLocation; 61 | } 62 | 63 | public int getUpdateInterval() { 64 | return updateInterval; 65 | } 66 | 67 | public DeploymentNotifierConfig getDeploymentNotifier() { 68 | return deploymentNotifier; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/ArtifactTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine; 17 | 18 | import org.testng.Assert; 19 | import org.testng.annotations.BeforeSuite; 20 | import org.testng.annotations.Test; 21 | 22 | import java.io.File; 23 | import java.util.HashMap; 24 | 25 | /** 26 | * Artifact test class which extends the BaseTest class. 27 | * 28 | * @since 5.0.0 29 | */ 30 | public class ArtifactTest extends BaseTest { 31 | private static final String DEPLOYER_REPO = "carbon-repo" + File.separator + "text-files"; 32 | private File file = new File(getTestResourceFile(DEPLOYER_REPO).getAbsolutePath() 33 | + File.separator + "sample1.txt"); 34 | private ArtifactType artifactType = new ArtifactType("txt"); 35 | 36 | private HashMap properties = new HashMap<>(); 37 | 38 | private Artifact artifact; 39 | 40 | /** 41 | * @param testName 42 | */ 43 | public ArtifactTest(String testName) { 44 | super(testName); 45 | } 46 | 47 | @BeforeSuite 48 | public void initialize() { 49 | artifact = new Artifact(file); 50 | properties.put("key1", "value1"); 51 | artifact.setProperties(properties); 52 | 53 | artifact.setType(artifactType); 54 | 55 | artifact.setKey("sample1.txt"); 56 | 57 | artifact.setVersion("1.0.0"); 58 | 59 | artifact.setLastModifiedTime(123456789); 60 | 61 | } 62 | 63 | @Test 64 | public void testArtifact() { 65 | Assert.assertEquals(artifact.getName(), "sample1.txt"); 66 | Assert.assertEquals(artifact.getVersion(), "1.0.0"); 67 | Assert.assertEquals(artifact.getFile().getAbsolutePath(), file.getAbsolutePath()); 68 | Assert.assertEquals(artifact.getKey(), "sample1.txt"); 69 | Assert.assertEquals(artifact.getType().get(), artifactType.get()); 70 | Assert.assertEquals(artifact.getLastModifiedTime(), 123456789); 71 | Assert.assertEquals(artifact.getPath(), file.getPath()); 72 | Assert.assertEquals(artifact.getProperties().get("key1"), properties.get("key1")); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/internal/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.internal; 17 | 18 | import org.wso2.carbon.deployment.engine.Artifact; 19 | 20 | import java.io.File; 21 | 22 | /** 23 | * A utility class for handling deployment engine related tasks such as check for artifact modification, etc. 24 | * 25 | * @since 5.0.0 26 | */ 27 | public class Utils { 28 | 29 | /** 30 | * Checks if a file has been modified by comparing the last update date of 31 | * both files and Artifact. If they are different, the file is assumed to have 32 | * been modified. 33 | * 34 | * @param artifact artifact to check for modification 35 | * @return boolean value of artifact modified or not 36 | */ 37 | public static boolean isArtifactModified(Artifact artifact) { 38 | long currentTimeStamp = artifact.getLastModifiedTime(); 39 | 40 | setArtifactLastModifiedTime(artifact); 41 | 42 | return (currentTimeStamp != artifact.getLastModifiedTime()); 43 | } 44 | 45 | /** 46 | * Sets the last modified time to the given artifact. 47 | * 48 | * @param artifact artifact for update modified time 49 | */ 50 | public static void setArtifactLastModifiedTime(Artifact artifact) { 51 | File file = artifact.getFile(); 52 | if (file != null && (artifact.getLastModifiedTime() < file.lastModified())) { 53 | artifact.setLastModifiedTime(file.lastModified()); 54 | } 55 | } 56 | 57 | /** 58 | * Request: file:sample.war . 59 | * Response: file:/user/wso2carbon-kernel-5.0.0/deployment/webapps/sample.war 60 | * 61 | * @param path file path to resolve 62 | * @param parentPath parent file path of the file 63 | * @return file with resolved path 64 | */ 65 | public static File resolveFileURL(String path, String parentPath) { 66 | if (path.contains(":") && !path.startsWith("file:")) { 67 | throw new RuntimeException("URLs other than file URLs are not supported."); 68 | } 69 | String relativeFilePath = path; 70 | if (path.startsWith("file:")) { 71 | relativeFilePath = path.substring(5); 72 | } 73 | 74 | File file = new File(relativeFilePath); 75 | if (!file.isAbsolute()) { 76 | file = new File(parentPath, relativeFilePath); 77 | if (!file.isAbsolute()) { 78 | throw new RuntimeException("Malformed URL : " + path); 79 | } 80 | } 81 | return file; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/config/DeploymentNotifierConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) $today.year, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.deployment.engine.config; 19 | 20 | import org.wso2.carbon.config.annotation.Configuration; 21 | import org.wso2.carbon.config.annotation.Element; 22 | 23 | import java.util.Optional; 24 | import java.util.Properties; 25 | 26 | /** 27 | * JAXB mapping for deployment notifier configuration. 28 | * 29 | * @since 5.1.0 30 | */ 31 | @Configuration(description = "Deployment notifier configuration parameters") 32 | public class DeploymentNotifierConfig { 33 | 34 | @Element(description = "JMS publishing enabled") 35 | private boolean jmsPublishingEnabled = false; 36 | 37 | @Element(description = "Desitination JNDI name") 38 | private String destinationJNDIName = "topic0"; 39 | 40 | @Element(description = "Destination type") 41 | private String destinationType = "topic"; 42 | 43 | @Element(description = "Java naming factory initial") 44 | private String javaNamingFactoryInitial = "org.wso2.andes.jndi.PropertiesFileInitialContextFactory"; 45 | 46 | @Element(description = "Java naming provider URL") 47 | private String javaNamingProviderURL = "conf/jndi.properties"; 48 | 49 | @Element(description = "JMS user name") 50 | private Optional jmsUsername = Optional.empty(); 51 | 52 | @Element(description = "JMS password") 53 | private Optional jmsPassword = Optional.empty(); 54 | 55 | @Element(description = "Connection factory JNDI name") 56 | private String connectionFactoryJNDIName = "TopicConnectionFactory"; 57 | 58 | @Element(description = "Static massage content") 59 | private Properties staticMessageContent = new Properties(); 60 | 61 | public boolean isJmsPublishingEnabled() { 62 | return jmsPublishingEnabled; 63 | } 64 | 65 | public String getDestinationJNDIName() { 66 | return destinationJNDIName; 67 | } 68 | 69 | public String getDestinationType() { 70 | return destinationType; 71 | } 72 | 73 | public Optional getJmsUsername() { 74 | return jmsUsername; 75 | } 76 | 77 | public Optional getJmsPassword() { 78 | return jmsPassword; 79 | } 80 | 81 | public String getJavaNamingFactoryInitial() { 82 | return javaNamingFactoryInitial; 83 | } 84 | 85 | public String getJavaNamingProviderURL() { 86 | return javaNamingProviderURL; 87 | } 88 | 89 | public String getConnectionFactoryJNDIName() { 90 | return connectionFactoryJNDIName; 91 | } 92 | 93 | public Properties getStaticMessageContent() { 94 | return Optional.ofNullable(staticMessageContent).orElse(new Properties()); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/deployers/FaultyDeployer2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.deployers; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | import org.wso2.carbon.deployment.engine.Artifact; 21 | import org.wso2.carbon.deployment.engine.ArtifactType; 22 | import org.wso2.carbon.deployment.engine.Deployer; 23 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 24 | 25 | import java.net.MalformedURLException; 26 | import java.net.URL; 27 | 28 | /** 29 | * A Faulty Deployer class to test deployment. 30 | * 31 | * @since 5.0.0 32 | */ 33 | public class FaultyDeployer2 implements Deployer { 34 | private static final Logger logger = LoggerFactory.getLogger(FaultyDeployer2.class); 35 | /** 36 | * Has init() been called?. 37 | */ 38 | public static boolean initCalled; 39 | /** 40 | * Set to true if "XML1" has been deployed. 41 | */ 42 | public static boolean sample1Deployed; 43 | /** 44 | * Set to true if "XML1" has been updated. 45 | */ 46 | public static boolean sample1Updated; 47 | 48 | private URL directoryLocation; 49 | private ArtifactType artifactType; 50 | 51 | public FaultyDeployer2() { 52 | artifactType = new ArtifactType<>("txt"); 53 | try { 54 | directoryLocation = new URL("file:text-files"); 55 | } catch (MalformedURLException e) { 56 | logger.error("Error while initializing directoryLocation", e); 57 | } 58 | } 59 | 60 | public void init() { 61 | logger.info("Initializing Deployer"); 62 | initCalled = true; 63 | } 64 | 65 | public String deploy(Artifact artifact) throws CarbonDeploymentException { 66 | logger.info("Deploying : " + artifact.getName()); 67 | sample1Deployed = false; 68 | return null; 69 | } 70 | 71 | public void undeploy(Object key) throws CarbonDeploymentException { 72 | logger.info("Undeploying : " + key); 73 | throw new CarbonDeploymentException("Error while Un Deploying : " + key); 74 | } 75 | 76 | public String update(Artifact artifact) throws CarbonDeploymentException { 77 | logger.info("Updating : " + artifact.getName()); 78 | sample1Updated = false; 79 | return null; 80 | } 81 | 82 | 83 | public URL getLocation() { 84 | return directoryLocation; 85 | } 86 | 87 | public void setLocation(URL directoryLocation) { 88 | this.directoryLocation = directoryLocation; 89 | } 90 | 91 | public ArtifactType getArtifactType() { 92 | return artifactType; 93 | } 94 | 95 | public void setArtifactType(ArtifactType artifactType) { 96 | this.artifactType = artifactType; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/deployers/FaultyDeployer1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.deployers; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | import org.wso2.carbon.deployment.engine.Artifact; 21 | import org.wso2.carbon.deployment.engine.ArtifactType; 22 | import org.wso2.carbon.deployment.engine.Deployer; 23 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 24 | 25 | import java.net.MalformedURLException; 26 | import java.net.URL; 27 | 28 | /** 29 | * A Faulty Deployer class to test deployment. 30 | * 31 | * @since 5.0.0 32 | */ 33 | public class FaultyDeployer1 implements Deployer { 34 | private static final Logger logger = LoggerFactory.getLogger(FaultyDeployer1.class); 35 | /** 36 | * Has init() been called?. 37 | */ 38 | public static boolean initCalled; 39 | /** 40 | * Set to true if "XML1" has been deployed. 41 | */ 42 | public static boolean sample1Deployed; 43 | /** 44 | * Set to true if "XML1" has been updated. 45 | */ 46 | public static boolean sample1Updated; 47 | 48 | private URL directoryLocation; 49 | private ArtifactType artifactType; 50 | 51 | public FaultyDeployer1() { 52 | artifactType = new ArtifactType<>("txt"); 53 | try { 54 | directoryLocation = new URL("file:text-files"); 55 | } catch (MalformedURLException e) { 56 | logger.error("Error while initializing directoryLocation", e); 57 | } 58 | } 59 | 60 | public void init() { 61 | logger.info("Initializing Deployer"); 62 | initCalled = true; 63 | } 64 | 65 | public String deploy(Artifact artifact) throws CarbonDeploymentException { 66 | logger.info("Deploying : " + artifact.getName()); 67 | sample1Deployed = false; 68 | throw new CarbonDeploymentException("Error while deploying : " + artifact.getName()); 69 | } 70 | 71 | public void undeploy(Object key) throws CarbonDeploymentException { 72 | logger.info("Undeploying : " + key); 73 | throw new CarbonDeploymentException("Error while Un Deploying : " + key); 74 | } 75 | 76 | public String update(Artifact artifact) throws CarbonDeploymentException { 77 | logger.info("Updating : " + artifact.getName()); 78 | sample1Updated = true; 79 | return artifact.getName(); 80 | } 81 | 82 | 83 | public URL getLocation() { 84 | return directoryLocation; 85 | } 86 | 87 | public void setLocation(URL directoryLocation) { 88 | this.directoryLocation = directoryLocation; 89 | } 90 | 91 | public ArtifactType getArtifactType() { 92 | return artifactType; 93 | } 94 | 95 | public void setArtifactType(ArtifactType artifactType) { 96 | this.artifactType = artifactType; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/java/org/wso2/carbon/deployment/notifier/BaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.notifier; 17 | 18 | import java.io.File; 19 | import java.io.FileInputStream; 20 | import java.io.FileNotFoundException; 21 | import java.io.InputStream; 22 | import java.net.URL; 23 | import java.nio.file.Path; 24 | import java.nio.file.Paths; 25 | import java.util.Optional; 26 | 27 | /** 28 | * BaseTest class for deployment tests. 29 | * 30 | * @since 5.0.0 31 | */ 32 | public class BaseTest { 33 | 34 | /** 35 | * Basedir for all file I/O. 36 | */ 37 | public static String basedir; 38 | private static final String OS_NAME_KEY = "os.name"; 39 | private static final String WINDOWS_PARAM = "Windows"; 40 | 41 | static { 42 | basedir = System.getProperty("basedir"); 43 | if (basedir == null) { 44 | basedir = new File(".").getAbsolutePath(); 45 | } 46 | } 47 | 48 | protected String testDir = "src" + File.separator + "test" + File.separator; 49 | protected String testResourceDir = testDir + "resources"; 50 | 51 | /** 52 | * @param testName 53 | */ 54 | public BaseTest(String testName) { 55 | testDir = new File(basedir, testDir).getAbsolutePath(); 56 | testResourceDir = new File(basedir, testResourceDir).getAbsolutePath(); 57 | } 58 | 59 | public File getTestResourceFile(String relativePath) { 60 | return new File(testResourceDir, relativePath); 61 | } 62 | 63 | public InputStream getTestResource(String relativePath) { 64 | File testResource = getTestResourceFile(relativePath); 65 | try { 66 | return new FileInputStream(testResource); 67 | } catch (FileNotFoundException e) { 68 | throw new IllegalStateException("The '" + testResource.getAbsolutePath() + 69 | "' file does not exist. Verify that the 'basedir' System property " + 70 | "is pointing to the root of the project", e); 71 | } 72 | } 73 | 74 | /** 75 | * Get the path of a provided resource. 76 | * 77 | * @param resourcePaths path strings to the location of the resource 78 | * @return path of the resources 79 | */ 80 | public Optional getResourcePath(String... resourcePaths) { 81 | URL resourceURL = BaseTest.class.getClassLoader().getResource(""); 82 | if (resourceURL != null) { 83 | String resourcePath = resourceURL.getPath(); 84 | if (resourcePath != null) { 85 | resourcePath = System.getProperty(OS_NAME_KEY).contains(WINDOWS_PARAM) ? 86 | resourcePath.substring(1) : resourcePath; 87 | return Optional.ofNullable(Paths.get(resourcePath, resourcePaths)); 88 | } 89 | } 90 | return Optional.empty(); // Resource do not exist 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/Deployer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine; 17 | 18 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 19 | 20 | import java.net.URL; 21 | 22 | /** 23 | * This interface is used to provide the custom deployment mechanism in carbon, where you 24 | * can write your own Deployer to process a particular {@link ArtifactType} 25 | *

26 | * A developer who wants write a deployer to process an artifact in carbon and add it to a 27 | * runtime configuration, should implement this. The implementation should then be registered 28 | * as an OSGi service using the Deployer interface for the DeploymentEngine to find and add 29 | * to the configuration 30 | * 31 | * @since 5.0.0 32 | */ 33 | 34 | public interface Deployer { 35 | 36 | /** 37 | * Initialize the Deployer. 38 | *

39 | * This will contain all the code that need to be called when the deployer is initialized 40 | */ 41 | void init(); 42 | 43 | /** 44 | * Process a deployable artifact and add it to the relevant runtime configuration. 45 | * 46 | * @param artifact the Artifact object to deploy 47 | * @return returns a key to uniquely identify an artifact within a runtime 48 | * @throws CarbonDeploymentException - when an error occurs while doing the deployment 49 | */ 50 | Object deploy(Artifact artifact) throws CarbonDeploymentException; 51 | 52 | /** 53 | * Remove a given artifact from the relevant runtime configuration. 54 | * 55 | * @param key the key of the deployed artifact used for undeploying it from the relevant runtime 56 | * @throws CarbonDeploymentException - when an error occurs while running the undeployment 57 | */ 58 | void undeploy(Object key) throws CarbonDeploymentException; 59 | 60 | 61 | /** 62 | * Updates a already deployed artifact and update its relevant runtime configuration. 63 | * 64 | * @param artifact the Artifact object to deploy 65 | * @return returns a key to uniquely identify an artifact within a runtime 66 | * @throws CarbonDeploymentException - when an error occurs while doing the deployment 67 | */ 68 | Object update(Artifact artifact) throws CarbonDeploymentException; 69 | 70 | /** 71 | * Returns the deploy directory location associated with the deployer. 72 | *

73 | * It can be relative to CARBON_HOME or an abosolute path 74 | * Eg : webapps, dataservices, sequences or 75 | * /dev/wso2/deployment/repository/ or 76 | * file:/dev/wso2/deployment/repository/ 77 | * 78 | * @return deployer directory location 79 | */ 80 | URL getLocation(); 81 | 82 | /** 83 | * Returns the type of the artifact that the deployer is capable of deploying. 84 | * Eg : webapp, dataservice 85 | * 86 | * @return ArtifactType object which contains info about the artifact type 87 | * @see ArtifactType 88 | */ 89 | ArtifactType getArtifactType(); 90 | 91 | } 92 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/DeployerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine; 17 | 18 | import org.testng.Assert; 19 | import org.testng.annotations.BeforeTest; 20 | import org.testng.annotations.Test; 21 | import org.wso2.carbon.deployment.engine.deployers.CustomDeployer; 22 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 23 | 24 | import java.io.File; 25 | import java.util.HashMap; 26 | 27 | /** 28 | * Deployer Test class. 29 | * 30 | * @since 5.0.0 31 | */ 32 | public class DeployerTest extends BaseTest { 33 | private static final String DEPLOYER_REPO = "carbon-repo" + File.separator + "text-files"; 34 | private static final String RUNTIME_DEPLOYER_REPO = "deployment" + File.separator + "text-files"; 35 | private CustomDeployer customDeployer; 36 | private Artifact artifact; 37 | private Artifact artifact2; 38 | private String key; 39 | private String key2; 40 | 41 | /** 42 | * @param testName 43 | */ 44 | public DeployerTest(String testName) { 45 | super(testName); 46 | } 47 | 48 | @BeforeTest 49 | public void setup() throws CarbonDeploymentException { 50 | customDeployer = new CustomDeployer(); 51 | customDeployer.init(); 52 | artifact = new Artifact(new File(getTestResourceFile(DEPLOYER_REPO).getAbsolutePath() 53 | + File.separator + "sample1.txt")); 54 | artifact.setVersion("1.0.0"); 55 | artifact.setProperties(new HashMap()); 56 | artifact2 = new Artifact(new File(getTestResourceFile(RUNTIME_DEPLOYER_REPO).getAbsolutePath() 57 | + File.separator + "sample2.txt")); 58 | artifact2.setVersion("1.0.0"); 59 | artifact2.setProperties(new HashMap()); 60 | } 61 | 62 | @Test 63 | public void testDeployerInitialization() { 64 | Assert.assertTrue(CustomDeployer.initCalled); 65 | } 66 | 67 | @Test(dependsOnMethods = {"testDeployerInitialization"}) 68 | public void testDeploy() throws CarbonDeploymentException { 69 | key = customDeployer.deploy(artifact); 70 | Assert.assertTrue(CustomDeployer.sample1Deployed); 71 | key2 = customDeployer.deploy(artifact2); 72 | Assert.assertTrue(CustomDeployer.sample2Deployed); 73 | } 74 | 75 | @Test(dependsOnMethods = {"testDeploy"}) 76 | public void testUpdate() throws CarbonDeploymentException { 77 | key = customDeployer.update(artifact); 78 | Assert.assertTrue(CustomDeployer.sample1Updated); 79 | key2 = customDeployer.update(artifact2); 80 | Assert.assertTrue(CustomDeployer.sample2Updated); 81 | } 82 | 83 | @Test(dependsOnMethods = {"testUpdate"}) 84 | public void testUnDeploy() throws CarbonDeploymentException { 85 | customDeployer.undeploy(key); 86 | Assert.assertFalse(CustomDeployer.sample1Deployed); 87 | customDeployer.undeploy(key2); 88 | Assert.assertFalse(CustomDeployer.sample2Deployed); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/java/org/wso2/carbon/deployment/notifier/DeployerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.notifier; 17 | 18 | import org.testng.Assert; 19 | import org.testng.annotations.BeforeTest; 20 | import org.testng.annotations.Test; 21 | import org.wso2.carbon.deployment.engine.Artifact; 22 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 23 | import org.wso2.carbon.deployment.notifier.deployers.CustomDeployer; 24 | 25 | import java.io.File; 26 | import java.util.HashMap; 27 | 28 | /** 29 | * Deployer Test class. 30 | * 31 | * @since 5.0.0 32 | */ 33 | public class DeployerTest extends BaseTest { 34 | private static final String DEPLOYER_REPO = "carbon-repo" + File.separator + "text-files"; 35 | private static final String RUNTIME_DEPLOYER_REPO = "deployment" + File.separator + "text-files"; 36 | private CustomDeployer customDeployer; 37 | private Artifact artifact; 38 | private Artifact artifact2; 39 | private String key; 40 | private String key2; 41 | /** 42 | * @param testName 43 | */ 44 | public DeployerTest(String testName) { 45 | super(testName); 46 | } 47 | 48 | @BeforeTest 49 | public void setup() throws CarbonDeploymentException { 50 | customDeployer = new CustomDeployer(); 51 | customDeployer.init(); 52 | artifact = new Artifact(new File(getTestResourceFile(DEPLOYER_REPO).getAbsolutePath() 53 | + File.separator + "sample1.txt")); 54 | artifact.setVersion("1.0.0"); 55 | artifact.setProperties(new HashMap<>()); 56 | artifact2 = new Artifact(new File(getTestResourceFile(RUNTIME_DEPLOYER_REPO).getAbsolutePath() 57 | + File.separator + "sample2.txt")); 58 | artifact2.setVersion("1.0.0"); 59 | artifact2.setProperties(new HashMap<>()); 60 | } 61 | 62 | @Test 63 | public void testDeployerInitialization() { 64 | Assert.assertTrue(CustomDeployer.initCalled); 65 | } 66 | 67 | @Test(dependsOnMethods = {"testDeployerInitialization"}) 68 | public void testDeploy() throws CarbonDeploymentException { 69 | key = customDeployer.deploy(artifact); 70 | Assert.assertTrue(CustomDeployer.sample1Deployed); 71 | key2 = customDeployer.deploy(artifact2); 72 | Assert.assertTrue(CustomDeployer.sample2Deployed); 73 | } 74 | 75 | @Test(dependsOnMethods = {"testDeploy"}) 76 | public void testUpdate() throws CarbonDeploymentException { 77 | key = customDeployer.update(artifact); 78 | Assert.assertTrue(CustomDeployer.sample1Updated); 79 | key2 = customDeployer.update(artifact2); 80 | Assert.assertTrue(CustomDeployer.sample2Updated); 81 | } 82 | 83 | @Test(dependsOnMethods = {"testUpdate"}) 84 | public void testUnDeploy() throws CarbonDeploymentException { 85 | customDeployer.undeploy(key); 86 | Assert.assertFalse(CustomDeployer.sample1Deployed); 87 | customDeployer.undeploy(key2); 88 | Assert.assertFalse(CustomDeployer.sample2Deployed); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/LifecycleEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.deployment.engine; 19 | 20 | import java.util.Date; 21 | import java.util.Optional; 22 | import java.util.Properties; 23 | 24 | /** 25 | * The deployment lifecycle of artifacts. An instance of this is passed 26 | * as part of the lifecycle event into the lifecycle listeners. 27 | * 28 | * @since 5.1.0 29 | * 30 | */ 31 | public class LifecycleEvent { 32 | 33 | /** 34 | * Represents the lifecycle state of the artifacts. 35 | * 36 | */ 37 | public enum STATE { 38 | BEFORE_START_EVENT, 39 | AFTER_START_EVENT, 40 | BEFORE_UPDATE_EVENT, 41 | AFTER_UPDATE_EVENT, 42 | BEFORE_STOP_EVENT, 43 | AFTER_STOP_EVENT 44 | } 45 | 46 | /** 47 | * The current artifact deployment/undeployment result. 48 | * If the artifact deployed/undeployed without any errors, 49 | * then the state will be successful denoting a successful artifact 50 | * deployment. 51 | * 52 | */ 53 | public enum RESULT { 54 | SUCCESSFUL, 55 | FAILED 56 | } 57 | 58 | private STATE state; 59 | 60 | private Artifact artifact; 61 | 62 | private Date timestamp; 63 | private RESULT deploymentResult; 64 | private String traceContent; 65 | 66 | public Properties properties = new Properties(); 67 | 68 | public LifecycleEvent(Artifact artifact, Date date, STATE state) { 69 | this.artifact = artifact; 70 | //assume a successful deployment initially. 71 | this.deploymentResult = RESULT.SUCCESSFUL; 72 | this.timestamp = Optional.ofNullable(date).map(tstamp -> new Date(date.getTime())).orElse(new Date()); 73 | this.state = state; 74 | } 75 | 76 | public STATE getState() { 77 | return state; 78 | } 79 | 80 | public void setState(STATE state) { 81 | this.state = state; 82 | } 83 | 84 | public Artifact getArtifact() { 85 | return artifact; 86 | } 87 | 88 | public void setArtifact(Artifact artifact) { 89 | this.artifact = artifact; 90 | } 91 | 92 | public Date getTimestamp() { 93 | return new Date(Optional.of(timestamp).get().getTime()); 94 | } 95 | 96 | public void setTimestamp(Date timestamp) { 97 | this.timestamp = new Date(timestamp.getTime()); 98 | } 99 | 100 | public RESULT getDeploymentResult() { 101 | return deploymentResult; 102 | } 103 | 104 | public void setDeploymentResult(RESULT deploymentResult) { 105 | this.deploymentResult = deploymentResult; 106 | } 107 | 108 | public String getTraceContent() { 109 | return traceContent; 110 | } 111 | 112 | public void setTraceContent(String traceContent) { 113 | this.traceContent = traceContent; 114 | } 115 | 116 | public Properties getProperties() { 117 | return properties; 118 | } 119 | 120 | public void setProperties(Properties properties) { 121 | this.properties = properties; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/DeploymentService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine; 17 | 18 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 19 | 20 | /** 21 | * User level API's for consuming DeploymentEngine functionality. 22 | * This will be registered as an OSGI service so that users can reference this in their component. 23 | *

24 | * If the given artifact type is not recognized at DeploymentEngine level or there is no deployer 25 | * associated with the give artifact type, then these API's will result in unknown artifact type 26 | * error. 27 | * 28 | * @since 5.0.0 29 | */ 30 | 31 | public interface DeploymentService { 32 | /** 33 | * User can call this method externally to deploy an artifact by giving the artifact deployment 34 | * directory and the path. 35 | * 36 | * @param artifactPath path where the artifact resides. This has to be the full qualified path 37 | * of the artifact 38 | * @param artifactType the type of the artifact going to be dpeloyed 39 | * Eg : webapp, dataservice, sequence 40 | * @throws CarbonDeploymentException - on error while trying deploy the given artifact info 41 | * @see ArtifactType 42 | */ 43 | void deploy(String artifactPath, ArtifactType artifactType) throws CarbonDeploymentException; 44 | 45 | /** 46 | * When you want to undeploy an artifact, this method can be called by giving the key, 47 | * which uniquely identifies an artifact in a runtime and the artifact deployment 48 | * directory. 49 | * 50 | * @param key artifact key to uniquely identify an artifact in a runtime 51 | * Eg: for webapps this can be webapp context such as /foo , /bar, etc 52 | * for service this can be service name such as EchoService, VersionService, etc 53 | * @param artifactType the type of the artifact going to be deployed 54 | * Eg : webapp, dataservice, sequence 55 | * @throws CarbonDeploymentException - on error while trying undeploy the given artifact info 56 | * @see ArtifactType 57 | */ 58 | void undeploy(Object key, ArtifactType artifactType) throws CarbonDeploymentException; 59 | 60 | /** 61 | * When you want to redeploy/update an artifact, this method can be called by giving the key, 62 | * which uniquely identifies an artifact in a runtime and the artifact deployment 63 | * directory. 64 | * 65 | * @param key artifact key to uniquely identify an artifact in a runtime 66 | * Eg: for webapps this can be webapp context such as /foo , /bar, etc 67 | * for service this can be service name such as EchoService, VersionService, etc 68 | * @param artifactType the type of the artifact going to be deployed 69 | * Eg : webapp, dataservice, sequence 70 | * @throws CarbonDeploymentException - on error while trying redeploy the given artifact info 71 | * @see ArtifactType 72 | */ 73 | void redeploy(Object key, ArtifactType artifactType) throws CarbonDeploymentException; 74 | } 75 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/internal/DataHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.internal; 17 | 18 | import org.osgi.framework.BundleContext; 19 | import org.wso2.carbon.config.provider.ConfigProvider; 20 | import org.wso2.carbon.deployment.engine.config.DeploymentConfiguration; 21 | import org.wso2.carbon.kernel.CarbonRuntime; 22 | 23 | /** 24 | * Carbon kernel DataHolder. 25 | * 26 | * @since 5.0.0 27 | */ 28 | public class DataHolder { 29 | private static DataHolder instance = new DataHolder(); 30 | private BundleContext bundleContext; 31 | 32 | private CarbonRuntime carbonRuntime; 33 | private ConfigProvider configProvider; 34 | private DeploymentConfiguration deploymentConfiguration; 35 | 36 | public static DataHolder getInstance() { 37 | return instance; 38 | } 39 | 40 | public BundleContext getBundleContext() { 41 | return bundleContext; 42 | } 43 | 44 | public void setBundleContext(BundleContext bundleContext) { 45 | this.bundleContext = bundleContext; 46 | } 47 | 48 | /** 49 | * This method used within this bundle (carbon.core) scope to get the currently held carbonRuntime service instance 50 | * within this holder. 51 | * 52 | * @return this will return the carbonRuntime service instance. 53 | */ 54 | public CarbonRuntime getCarbonRuntime() { 55 | return carbonRuntime; 56 | } 57 | 58 | /** 59 | * This method is called by the relevant service component that acquires the carbonRuntime service 60 | * instance and will be stored for future look-ups. 61 | * 62 | * @param carbonRuntime the carbonRuntime to be stored with this holder 63 | */ 64 | public void setCarbonRuntime(CarbonRuntime carbonRuntime) { 65 | this.carbonRuntime = carbonRuntime; 66 | } 67 | 68 | /** 69 | * This method is called to set the config provider service. 70 | * 71 | * @param configProvider the configProvider to be stored with this holder. 72 | */ 73 | public void setConfigProvider(ConfigProvider configProvider) { 74 | 75 | this.configProvider = configProvider; 76 | } 77 | 78 | /** 79 | * This method is used to get the config provider service. 80 | * 81 | * @return this will return the configProvider service instance. 82 | */ 83 | public ConfigProvider getConfigProvider() { 84 | return configProvider; 85 | } 86 | 87 | /** 88 | * This method is used to get the deploymentConfig. 89 | * 90 | * @return this will return the deploymentConfig instance. 91 | */ 92 | public DeploymentConfiguration getDeploymentConfiguration() { 93 | return deploymentConfiguration; 94 | } 95 | 96 | /** 97 | * This method is called to set the deploymentConfig object. 98 | * 99 | * @param deploymentConfiguration the deploymentConfig to be stored with this holder. 100 | */ 101 | public void setDeploymentConfiguration(DeploymentConfiguration deploymentConfiguration) { 102 | this.deploymentConfiguration = deploymentConfiguration; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/service/CustomDeploymentService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.service; 17 | 18 | import org.wso2.carbon.deployment.engine.Artifact; 19 | import org.wso2.carbon.deployment.engine.ArtifactType; 20 | import org.wso2.carbon.deployment.engine.Deployer; 21 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 22 | import org.wso2.carbon.deployment.engine.internal.CarbonDeploymentService; 23 | import org.wso2.carbon.deployment.engine.internal.DeploymentEngine; 24 | 25 | import java.io.File; 26 | import java.util.ArrayList; 27 | 28 | /** 29 | * Custom Deployment Service class. 30 | * 31 | * @since 5.0.0 32 | */ 33 | public class CustomDeploymentService extends CarbonDeploymentService { 34 | 35 | private DeploymentEngine deploymentEngine; 36 | 37 | public CustomDeploymentService(DeploymentEngine deploymentEngine) { 38 | super(deploymentEngine); 39 | this.deploymentEngine = deploymentEngine; 40 | } 41 | 42 | @Override 43 | public void deploy(String artifactPath, ArtifactType artifactType) 44 | throws CarbonDeploymentException { 45 | try { 46 | super.deploy("fake/path", artifactType); 47 | } catch (CarbonDeploymentException e) { 48 | //ignore 49 | } 50 | Artifact artifact = new Artifact(new File(artifactPath)); 51 | artifact.setType(artifactType); 52 | ArrayList artifactList = new ArrayList<>(); 53 | artifactList.add(artifact); 54 | Deployer deployer = deploymentEngine.getDeployer(artifactType); 55 | 56 | if (deployer == null) { 57 | throw new CarbonDeploymentException("Unknown artifactType : " + artifactType); 58 | } 59 | deploymentEngine.deployArtifacts(artifactList); 60 | } 61 | 62 | @Override 63 | public void undeploy(Object key, ArtifactType artifactType) throws CarbonDeploymentException { 64 | try { 65 | super.undeploy("fake.key", artifactType); 66 | } catch (CarbonDeploymentException e) { 67 | // ignore 68 | } 69 | Deployer deployer = deploymentEngine.getDeployer(artifactType); 70 | 71 | if (deployer == null) { 72 | throw new CarbonDeploymentException("Unknown artifactType : " + artifactType); 73 | } 74 | deployer.undeploy(key); 75 | } 76 | 77 | @Override 78 | public void redeploy(Object key, ArtifactType artifactType) throws CarbonDeploymentException { 79 | 80 | try { 81 | super.redeploy("fake.key", artifactType); 82 | } catch (CarbonDeploymentException e) { 83 | // ignore 84 | } 85 | Deployer deployer = deploymentEngine.getDeployer(artifactType); 86 | if (deployer == null) { 87 | throw new CarbonDeploymentException("Unknown artifactType : " + artifactType); 88 | } 89 | 90 | Artifact deployedArtifact = deploymentEngine.getDeployedArtifact(artifactType, key); 91 | 92 | if (deployedArtifact == null) { 93 | throw new CarbonDeploymentException("Cannot find artifact with the key : " + key); 94 | } 95 | 96 | deployer.update(deployedArtifact); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/java/org/wso2/carbon/deployment/notifier/service/CustomDeploymentService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.notifier.service; 17 | 18 | import org.wso2.carbon.deployment.engine.Artifact; 19 | import org.wso2.carbon.deployment.engine.ArtifactType; 20 | import org.wso2.carbon.deployment.engine.Deployer; 21 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 22 | import org.wso2.carbon.deployment.engine.internal.CarbonDeploymentService; 23 | import org.wso2.carbon.deployment.engine.internal.DeploymentEngine; 24 | 25 | import java.io.File; 26 | import java.util.ArrayList; 27 | 28 | /** 29 | * Custom Deployment Service class. 30 | * 31 | * @since 5.0.0 32 | */ 33 | public class CustomDeploymentService extends CarbonDeploymentService { 34 | 35 | private DeploymentEngine deploymentEngine; 36 | 37 | public CustomDeploymentService(DeploymentEngine deploymentEngine) { 38 | super(deploymentEngine); 39 | this.deploymentEngine = deploymentEngine; 40 | } 41 | 42 | @Override 43 | public void deploy(String artifactPath, ArtifactType artifactType) 44 | throws CarbonDeploymentException { 45 | try { 46 | super.deploy("fake/path", artifactType); 47 | } catch (CarbonDeploymentException e) { 48 | //ignore 49 | } 50 | Artifact artifact = new Artifact(new File(artifactPath)); 51 | artifact.setType(artifactType); 52 | ArrayList artifactList = new ArrayList<>(); 53 | artifactList.add(artifact); 54 | Deployer deployer = deploymentEngine.getDeployer(artifactType); 55 | 56 | if (deployer == null) { 57 | throw new CarbonDeploymentException("Unknown artifactType : " + artifactType); 58 | } 59 | deploymentEngine.deployArtifacts(artifactList); 60 | } 61 | 62 | @Override 63 | public void undeploy(Object key, ArtifactType artifactType) throws CarbonDeploymentException { 64 | try { 65 | super.undeploy("fake.key", artifactType); 66 | } catch (CarbonDeploymentException e) { 67 | // ignore 68 | } 69 | Deployer deployer = deploymentEngine.getDeployer(artifactType); 70 | 71 | if (deployer == null) { 72 | throw new CarbonDeploymentException("Unknown artifactType : " + artifactType); 73 | } 74 | deployer.undeploy(key); 75 | } 76 | 77 | @Override 78 | public void redeploy(Object key, ArtifactType artifactType) throws CarbonDeploymentException { 79 | 80 | try { 81 | super.redeploy("fake.key", artifactType); 82 | } catch (CarbonDeploymentException e) { 83 | // ignore 84 | } 85 | Deployer deployer = deploymentEngine.getDeployer(artifactType); 86 | if (deployer == null) { 87 | throw new CarbonDeploymentException("Unknown artifactType : " + artifactType); 88 | } 89 | 90 | Artifact deployedArtifact = deploymentEngine.getDeployedArtifact(artifactType, key); 91 | 92 | if (deployedArtifact == null) { 93 | throw new CarbonDeploymentException("Cannot find artifact with the key : " + key); 94 | } 95 | 96 | deployer.update(deployedArtifact); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Carbon Deployment 2 | 3 | --- 4 | 5 | | Branch | Build Status | 6 | | :------------ |:------------- 7 | | master | [![Build Status](https://wso2.org/jenkins/job/carbon-deployment/badge/icon)](https://wso2.org/jenkins/job/carbon-deployment) | 8 | | release-4.2.x | [![Build Status](https://wso2.org/jenkins/job/carbon-deployment_release-4.2.x/badge/icon)](https://wso2.org/jenkins/job/carbon-deployment_release-4.2.x/) | 9 | 10 | 11 | --- 12 | Carbon 5.x artifact deployment framework - This is an extensible framework where Carbon developers get to incorporate and write their own artifact deployers to deploy its artifacts into a Carbon 5 based product. 13 | 14 | This provides following interfaces - 15 | * `DeploymentService` - 16 | 17 | User level API for consuming `DeploymentEngine` functionality. An implementation of this is registered as an OSGI service which can be used by developers to deploy/undeploy/redeploy their artifacts. 18 | 19 | * `Deployer` - 20 | 21 | This interface is used to provide the deployment mechanism in carbon for custom artifacts, where you can write your own Deployer to process a particular ArtifactType. Developers need to develop implementations based on this interface, and register it as an OSGi service (using the Deployer as the interface) for the DeploymentEngine to find. 22 | 23 | * `LifecycleListener` - 24 | 25 | This interface can be used to write your own lifecycle listeners to listen on artifact deployment events. The implementation should be registered as an OSGi service with LifecycleListener as the interface. This interface receives following events. 26 | 27 | ```bash 28 | BEFORE_START_EVENT 29 | AFTER_START_EVENT 30 | BEFORE_STOP_EVENT 31 | AFTER_STOP_EVENT 32 | ``` 33 | 34 | ## Download 35 | 36 | Use Maven snippet: 37 | ````xml 38 | 39 | org.wso2.carbon.deployment 40 | org.wso2.carbon.deployment.engine 41 | ${carbon.deployment.version} 42 | 43 | 44 | 45 | org.wso2.carbon.deployment 46 | org.wso2.carbon.deployment.notifier 47 | ${carbon.deployment.version} 48 | 49 | ```` 50 | 51 | ### Snapshot Releases 52 | 53 | Use following Maven repository for snapshot versions of Carbon Deployment. 54 | 55 | ````xml 56 | 57 | wso2.snapshots 58 | WSO2 Snapshot Repository 59 | http://maven.wso2.org/nexus/content/repositories/snapshots/ 60 | 61 | true 62 | daily 63 | 64 | 65 | false 66 | 67 | 68 | ```` 69 | 70 | ### Released Versions 71 | 72 | Use following Maven repository for released stable versions of Carbon Deployment. 73 | 74 | ````xml 75 | 76 | wso2.releases 77 | WSO2 Releases Repository 78 | http://maven.wso2.org/nexus/content/repositories/releases/ 79 | 80 | true 81 | daily 82 | ignore 83 | 84 | 85 | ```` 86 | ## Building From Source 87 | 88 | Clone this repository first (`git clone https://github.com/wso2/carbon-deployment.git`) and use Apache Maven to build `mvn clean install`. 89 | 90 | 91 | ## How to Contribute 92 | * Please report issues at [Carbon JIRA] (https://wso2.org/jira/browse/CARBON). 93 | * Send your pull requests to [master branch] (https://github.com/wso2/carbon-deployment/tree/master) 94 | 95 | ## License 96 | 97 | Carbon Deployment is available under the Apache 2 License. 98 | 99 | ## Contact us 100 | WSO2 Carbon developers can be contacted via the mailing lists: 101 | 102 | * Carbon Developers List : dev@wso2.org 103 | * Carbon Architecture List : architecture@wso2.org 104 | 105 | ## Copyright 106 | 107 | Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 108 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/DeploymentServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine; 17 | 18 | import org.testng.Assert; 19 | import org.testng.annotations.AfterTest; 20 | import org.testng.annotations.BeforeTest; 21 | import org.testng.annotations.Test; 22 | import org.wso2.carbon.deployment.engine.deployers.CustomDeployer; 23 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 24 | import org.wso2.carbon.deployment.engine.exception.DeployerRegistrationException; 25 | import org.wso2.carbon.deployment.engine.exception.DeploymentEngineException; 26 | import org.wso2.carbon.deployment.engine.internal.DeploymentEngine; 27 | import org.wso2.carbon.deployment.engine.service.CustomDeploymentService; 28 | import org.wso2.carbon.utils.FileUtils; 29 | 30 | import java.io.File; 31 | import java.io.IOException; 32 | 33 | /** 34 | * Deployment Service Test class. 35 | * 36 | * @since 5.0.0 37 | */ 38 | public class DeploymentServiceTest extends BaseTest { 39 | 40 | private static final String CARBON_REPO = "carbon-repo"; 41 | private static final String RUNTIME_REPO = "deployment"; 42 | private static final String DEPLOYER_REPO = "carbon-repo" + File.separator + "text-files"; 43 | private CustomDeploymentService deploymentService; 44 | private DeploymentEngine deploymentEngine; 45 | private CustomDeployer customDeployer; 46 | private String artifactPath; 47 | 48 | /** 49 | * @param testName 50 | */ 51 | public DeploymentServiceTest(String testName) { 52 | super(testName); 53 | } 54 | 55 | @BeforeTest 56 | public void setup() throws DeploymentEngineException, DeployerRegistrationException { 57 | customDeployer = new CustomDeployer(); 58 | artifactPath = getTestResourceFile(DEPLOYER_REPO).getAbsolutePath() 59 | + File.separator + "sample1.txt"; 60 | deploymentEngine = new DeploymentEngine(); 61 | deploymentEngine.start(getTestResourceFile(CARBON_REPO).getAbsolutePath(), 62 | getTestResourceFile(DEPLOYER_REPO).getAbsolutePath()); 63 | deploymentEngine.registerDeployer(customDeployer); 64 | } 65 | 66 | @Test 67 | public void testDeploymentService() { 68 | deploymentService = new CustomDeploymentService(deploymentEngine); 69 | } 70 | 71 | @Test(dependsOnMethods = {"testDeploymentService"}) 72 | public void testDeploy() throws CarbonDeploymentException { 73 | deploymentService.deploy(artifactPath, customDeployer.getArtifactType()); 74 | Assert.assertTrue(CustomDeployer.sample1Deployed); 75 | } 76 | 77 | @Test(dependsOnMethods = {"testDeploy"}) 78 | public void testUpdate() throws CarbonDeploymentException { 79 | deploymentService.redeploy(new File(artifactPath).getName(), 80 | customDeployer.getArtifactType()); 81 | Assert.assertTrue(CustomDeployer.sample1Updated); 82 | } 83 | 84 | @Test(dependsOnMethods = {"testUpdate"}) 85 | public void testUndeploy() throws CarbonDeploymentException { 86 | deploymentService.undeploy(new File(artifactPath).getName(), 87 | customDeployer.getArtifactType()); 88 | Assert.assertFalse(CustomDeployer.sample1Deployed); 89 | } 90 | 91 | @AfterTest 92 | public void cleanupTempfile() throws IOException { 93 | FileUtils.deleteDir(new File(getTestResourceFile(CARBON_REPO).getAbsolutePath() + 94 | File.separator + "file:text-files")); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/java/org/wso2/carbon/deployment/notifier/deployers/FaultyDeployer2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.notifier.deployers; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | import org.wso2.carbon.deployment.engine.Artifact; 21 | import org.wso2.carbon.deployment.engine.ArtifactType; 22 | import org.wso2.carbon.deployment.engine.Deployer; 23 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 24 | 25 | import java.net.MalformedURLException; 26 | import java.net.URL; 27 | 28 | /** 29 | * A Faulty Deployer class to test deployment. 30 | * 31 | * @since 5.0.0 32 | */ 33 | public class FaultyDeployer2 implements Deployer { 34 | private static final Logger logger = LoggerFactory.getLogger(FaultyDeployer2.class); 35 | /** 36 | * Has init() been called?. 37 | */ 38 | public static boolean initCalled; 39 | /** 40 | * Set to true if "XML1" has been deployed. 41 | */ 42 | public static boolean sample1Deployed; 43 | /** 44 | * Set to true if "XML2" has been deployed. 45 | */ 46 | public static boolean sample2Deployed; 47 | /** 48 | * Set to true if "XML1" has been updated. 49 | */ 50 | public static boolean sample1Updated; 51 | /** 52 | * Set to true if "XML1" has been updated. 53 | */ 54 | public static boolean sample2Updated; 55 | 56 | private URL directoryLocation; 57 | private ArtifactType artifactType; 58 | 59 | public FaultyDeployer2() { 60 | artifactType = new ArtifactType<>("txt"); 61 | try { 62 | directoryLocation = new URL("file:text-files"); 63 | } catch (MalformedURLException e) { 64 | logger.error("Error while initializing directoryLocation", e); 65 | } 66 | } 67 | 68 | public void init() { 69 | logger.info("Initializing Deployer"); 70 | initCalled = true; 71 | } 72 | 73 | public String deploy(Artifact artifact) throws CarbonDeploymentException { 74 | logger.info("Deploying : " + artifact.getName()); 75 | if (artifact.getName() != null && artifact.getName().contains("sample1.txt")) { 76 | sample1Deployed = false; 77 | } else if (artifact.getName() != null && artifact.getName().contains("sample2.txt")) { 78 | sample2Deployed = false; 79 | } 80 | return null; 81 | } 82 | 83 | public void undeploy(Object key) throws CarbonDeploymentException { 84 | logger.info("Undeploying : " + key); 85 | throw new CarbonDeploymentException("Error while Un Deploying : " + key); 86 | } 87 | 88 | public String update(Artifact artifact) throws CarbonDeploymentException { 89 | logger.info("Updating : " + artifact.getName()); 90 | if (artifact.getName() != null && artifact.getName().contains("sample1.txt")) { 91 | sample1Updated = false; 92 | } else if (artifact.getName().contains("sample2.txt")) { 93 | sample2Updated = false; 94 | } 95 | return null; 96 | } 97 | 98 | 99 | public URL getLocation() { 100 | return directoryLocation; 101 | } 102 | 103 | public void setLocation(URL directoryLocation) { 104 | this.directoryLocation = directoryLocation; 105 | } 106 | 107 | public ArtifactType getArtifactType() { 108 | return artifactType; 109 | } 110 | 111 | public void setArtifactType(ArtifactType artifactType) { 112 | this.artifactType = artifactType; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/java/org/wso2/carbon/deployment/notifier/deployers/FaultyDeployer1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.notifier.deployers; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | import org.wso2.carbon.deployment.engine.Artifact; 21 | import org.wso2.carbon.deployment.engine.ArtifactType; 22 | import org.wso2.carbon.deployment.engine.Deployer; 23 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 24 | 25 | import java.net.MalformedURLException; 26 | import java.net.URL; 27 | 28 | /** 29 | * A Faulty Deployer class to test deployment. 30 | * 31 | * @since 5.0.0 32 | */ 33 | public class FaultyDeployer1 implements Deployer { 34 | private static final Logger logger = LoggerFactory.getLogger(FaultyDeployer1.class); 35 | /** 36 | * Has init() been called?. 37 | */ 38 | public static boolean initCalled; 39 | /** 40 | * Set to true if "XML1" has been deployed. 41 | */ 42 | public static boolean sample1Deployed; 43 | /** 44 | * Set to true if "XML2" has been deployed. 45 | */ 46 | public static boolean sample2Deployed; 47 | /** 48 | * Set to true if "XML1" has been updated. 49 | */ 50 | public static boolean sample1Updated; 51 | /** 52 | * Set to true if "XML2" has been updated. 53 | */ 54 | public static boolean sample2Updated; 55 | 56 | private URL directoryLocation; 57 | private ArtifactType artifactType; 58 | 59 | public FaultyDeployer1() { 60 | artifactType = new ArtifactType<>("txt"); 61 | try { 62 | directoryLocation = new URL("file:text-files"); 63 | } catch (MalformedURLException e) { 64 | logger.error("Error while initializing directoryLocation", e); 65 | } 66 | } 67 | 68 | public void init() { 69 | logger.info("Initializing Deployer"); 70 | initCalled = true; 71 | } 72 | 73 | public String deploy(Artifact artifact) throws CarbonDeploymentException { 74 | logger.info("Deploying : " + artifact.getName()); 75 | if (artifact.getName() != null && artifact.getName().contains("sample1.txt")) { 76 | sample1Deployed = false; 77 | } else if (artifact.getName() != null && artifact.getName().contains("sample2.txt")) { 78 | sample2Deployed = false; 79 | } 80 | throw new CarbonDeploymentException("Error while deploying : " + artifact.getName()); 81 | } 82 | 83 | public void undeploy(Object key) throws CarbonDeploymentException { 84 | logger.info("Undeploying : " + key); 85 | throw new CarbonDeploymentException("Error while Un Deploying : " + key); 86 | } 87 | 88 | public String update(Artifact artifact) throws CarbonDeploymentException { 89 | logger.info("Updating : " + artifact.getName()); 90 | if (artifact.getName() != null && artifact.getName().contains("sample1.txt")) { 91 | sample1Updated = true; 92 | } else if (artifact.getName() != null && artifact.getName().contains("sample2.txt")) { 93 | sample2Updated = true; 94 | } 95 | return artifact.getName(); 96 | } 97 | 98 | 99 | public URL getLocation() { 100 | return directoryLocation; 101 | } 102 | 103 | public void setLocation(URL directoryLocation) { 104 | this.directoryLocation = directoryLocation; 105 | } 106 | 107 | public ArtifactType getArtifactType() { 108 | return artifactType; 109 | } 110 | 111 | public void setArtifactType(ArtifactType artifactType) { 112 | this.artifactType = artifactType; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /tests/osgi-tests/src/test/java/org/wso2/carbon/deployment/engine/osgi/CustomDeployer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.osgi; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | import org.wso2.carbon.deployment.engine.Artifact; 21 | import org.wso2.carbon.deployment.engine.ArtifactType; 22 | import org.wso2.carbon.deployment.engine.Deployer; 23 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 24 | 25 | import java.io.File; 26 | import java.io.FileInputStream; 27 | import java.io.IOException; 28 | import java.net.MalformedURLException; 29 | import java.net.URL; 30 | 31 | /** 32 | * Custom Deployer class to test deployment engine OSGi test case. 33 | * 34 | * @since 5.0.0 35 | */ 36 | public class CustomDeployer implements Deployer { 37 | private static final Logger logger = LoggerFactory.getLogger(CustomDeployer.class); 38 | 39 | private String directory = "carbon-repo/text-files"; 40 | private URL directoryLocation; 41 | private ArtifactType artifactType; 42 | private String testDir = "src" + File.separator + "test" + File.separator + "resources" + 43 | File.separator + "carbon-repo" + File.separator + directory; 44 | 45 | public CustomDeployer() { 46 | artifactType = new ArtifactType<>("txt"); 47 | try { 48 | directoryLocation = new URL("file:text-files"); 49 | } catch (MalformedURLException e) { 50 | logger.error("Error while initializing directoryLocation", e); 51 | } 52 | } 53 | 54 | public void init() { 55 | logger.info("Initializing Deployer"); 56 | } 57 | 58 | public String deploy(Artifact artifact) throws CarbonDeploymentException { 59 | logger.info("Deploying : " + artifact.getName()); 60 | String key = null; 61 | try (FileInputStream fis = new FileInputStream(artifact.getFile())) { 62 | int x = fis.available(); 63 | byte b[] = new byte[x]; 64 | fis.read(b); 65 | String content = new String(b); 66 | if (content.contains("sample1")) { 67 | key = artifact.getName(); 68 | } 69 | } catch (IOException e) { 70 | throw new CarbonDeploymentException("Error while deploying : " + artifact.getName(), e); 71 | } 72 | return key; 73 | } 74 | 75 | public void undeploy(Object key) throws CarbonDeploymentException { 76 | if (!(key instanceof String)) { 77 | throw new CarbonDeploymentException("Error while Un Deploying : " + key + 78 | "is not a String value"); 79 | } 80 | logger.info("Undeploying : " + key); 81 | File fileToUndeploy = new File(testDir + File.separator + key); 82 | logger.info("File to undeploy : " + fileToUndeploy.getAbsolutePath()); 83 | try (FileInputStream fis = new FileInputStream(fileToUndeploy)) { 84 | int x = fis.available(); 85 | byte b[] = new byte[x]; 86 | fis.read(b); 87 | String content = new String(b); 88 | if (content.contains("sample1")) { 89 | logger.info("Undeployed : " + key); 90 | } 91 | } catch (IOException e) { 92 | throw new CarbonDeploymentException("Error while Un Deploying : " + key, e); 93 | } 94 | } 95 | 96 | public String update(Artifact artifact) throws CarbonDeploymentException { 97 | logger.info("Updating : " + artifact.getName()); 98 | return artifact.getName(); 99 | } 100 | 101 | 102 | public URL getLocation() { 103 | return directoryLocation; 104 | } 105 | 106 | public void setLocation(URL directoryLocation) { 107 | this.directoryLocation = directoryLocation; 108 | } 109 | 110 | public ArtifactType getArtifactType() { 111 | return artifactType; 112 | } 113 | 114 | public void setArtifactType(ArtifactType artifactType) { 115 | this.artifactType = artifactType; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /features/org.wso2.carbon.deployment.notifier.feature/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | org.wso2.carbon.deployment 21 | org.wso2.carbon.deployment.parent 22 | 5.1.8-SNAPSHOT 23 | ../../pom.xml 24 | 25 | 26 | 4.0.0 27 | org.wso2.carbon.deployment.notifier.feature 28 | 5.1.8-SNAPSHOT 29 | carbon-feature 30 | 31 | WSO2 Carbon Deployment Notifier - Feature 32 | http://wso2.org 33 | This feature contains the core bundles required by the Deployment feature 34 | 35 | 36 | 37 | org.wso2.carbon.deployment 38 | org.wso2.carbon.deployment.notifier 39 | 40 | 41 | org.apache.geronimo.specs 42 | geronimo-jms_1.1_spec 43 | 44 | 45 | commons-pool.wso2 46 | commons-pool 47 | 48 | 49 | 50 | 51 | 52 | 53 | resources 54 | 55 | 56 | src/main/resources 57 | 58 | 59 | 60 | 61 | org.wso2.carbon.maven 62 | carbon-feature-plugin 63 | true 64 | 65 | 66 | 1-p2-feature-generation 67 | 68 | generate 69 | 70 | 71 | ../etc/feature.properties 72 | 73 | 74 | org.wso2.carbon.p2.category.type 75 | server 76 | 77 | 78 | org.eclipse.equinox.p2.type.group 79 | false 80 | 81 | 82 | 83 | 84 | org.wso2.carbon.deployment.notifier 85 | ${carbon.deployment.version} 86 | 87 | 88 | org.apache.geronimo.specs.geronimo-jms_1.1_spec 89 | ${geronimo.jms.spec.version} 90 | 91 | 92 | commons-pool 93 | ${commons.pool.version} 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/main/java/org/wso2/carbon/deployment/notifier/internal/DeploymentNotificationMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * WSO2 Inc. licenses this file to you under the Apache License, 5 | * Version 2.0 (the "License"); you may not use this file except 6 | * in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, 12 | * software distributed under the License is distributed on an 13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | * KIND, either express or implied. See the License for the 15 | * specific language governing permissions and limitations 16 | * under the License. 17 | */ 18 | package org.wso2.carbon.deployment.notifier.internal; 19 | 20 | import org.wso2.carbon.deployment.engine.Artifact; 21 | import org.wso2.carbon.deployment.engine.LifecycleEvent; 22 | 23 | import java.util.Date; 24 | import java.util.Optional; 25 | import java.util.Properties; 26 | import javax.xml.bind.annotation.XmlAccessType; 27 | import javax.xml.bind.annotation.XmlAccessorType; 28 | import javax.xml.bind.annotation.XmlElement; 29 | import javax.xml.bind.annotation.XmlRootElement; 30 | 31 | /** 32 | * The JAXB POJO that is used to send the artifact deployment 33 | * status, usually to a JMS topic. 34 | * 35 | * @since 5.0.0 36 | * 37 | */ 38 | @XmlRootElement 39 | @XmlAccessorType(XmlAccessType.FIELD) 40 | public class DeploymentNotificationMessage { 41 | 42 | @XmlElement 43 | private Object artifactKey; 44 | 45 | @XmlElement 46 | private String artifactType; 47 | 48 | @XmlElement 49 | private String serverId; 50 | 51 | @XmlElement 52 | private Date timestamp; 53 | 54 | @XmlElement 55 | private LifecycleEvent.RESULT currentDeploymentResult; 56 | 57 | @XmlElement 58 | private LifecycleEvent.STATE lifecycleState; 59 | 60 | @XmlElement 61 | private String message; 62 | 63 | @XmlElement 64 | public Properties properties; 65 | 66 | public DeploymentNotificationMessage(Artifact artifact) { 67 | this(artifact, null); 68 | } 69 | 70 | /** 71 | * The default constructor is required by JAXB 72 | * to do serialization. 73 | */ 74 | public DeploymentNotificationMessage() { 75 | } 76 | 77 | /** 78 | * Extracts info from the Artifact object. 79 | * 80 | * @param artifact The artifact that we need to extract info from 81 | */ 82 | public DeploymentNotificationMessage(Artifact artifact, Date timestamp) { 83 | this.artifactKey = artifact.getKey(); 84 | this.artifactType = artifact.getType().get().toString(); 85 | this.timestamp = Optional.ofNullable(timestamp).map(tstamp -> new Date(timestamp.getTime())).orElse(new Date()); 86 | } 87 | 88 | public Object getArtifactKey() { 89 | return artifactKey; 90 | } 91 | 92 | public void setArtifactKey(Object artifactKey) { 93 | this.artifactKey = artifactKey; 94 | } 95 | 96 | public String getArtifactType() { 97 | return artifactType; 98 | } 99 | 100 | public void setArtifactType(String artifactType) { 101 | this.artifactType = artifactType; 102 | } 103 | 104 | public String getServerId() { 105 | return serverId; 106 | } 107 | 108 | public void setServerId(String host) { 109 | this.serverId = host; 110 | } 111 | 112 | public Date getTimestamp() { 113 | return new Date(timestamp.getTime()); 114 | } 115 | 116 | public void setTimestamp(Date timestamp) { 117 | this.timestamp = new Date(timestamp.getTime()); 118 | } 119 | 120 | public LifecycleEvent.STATE getLifecycleState() { 121 | return lifecycleState; 122 | } 123 | 124 | public void setLifecycleState(LifecycleEvent.STATE lifecycleState) { 125 | this.lifecycleState = lifecycleState; 126 | } 127 | 128 | public LifecycleEvent.RESULT getCurrentDeploymentResult() { 129 | return currentDeploymentResult; 130 | } 131 | 132 | public void setCurrentDeploymentResult(LifecycleEvent.RESULT currentDeploymentResult) { 133 | this.currentDeploymentResult = currentDeploymentResult; 134 | } 135 | 136 | public String getMessage() { 137 | return message; 138 | } 139 | 140 | public void setTraceContent(String message) { 141 | this.message = message; 142 | } 143 | 144 | public Properties getProperties() { 145 | return properties; 146 | } 147 | 148 | public void setProperties(Properties properties) { 149 | this.properties = properties; 150 | } 151 | 152 | @Override 153 | public String toString() { 154 | return String.format("%1$s - %2$s - %3$s ", artifactKey, artifactType, lifecycleState); 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/java/org/wso2/carbon/deployment/notifier/DeploymentServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.notifier; 17 | 18 | import org.testng.Assert; 19 | import org.testng.annotations.AfterTest; 20 | import org.testng.annotations.BeforeTest; 21 | import org.testng.annotations.Test; 22 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 23 | import org.wso2.carbon.deployment.engine.internal.DeploymentEngine; 24 | import org.wso2.carbon.deployment.notifier.deployers.CustomDeployer; 25 | import org.wso2.carbon.deployment.notifier.service.CustomDeploymentService; 26 | import org.wso2.carbon.utils.FileUtils; 27 | 28 | import java.io.File; 29 | import java.io.IOException; 30 | 31 | /** 32 | * Deployment Service Test class. 33 | * 34 | * @since 5.0.0 35 | */ 36 | public class DeploymentServiceTest extends BaseTest { 37 | 38 | private static final String CARBON_REPO = "carbon-repo"; 39 | private static final String RUNTIME_REPO = "deployment"; 40 | private static final String DEPLOYER_REPO = CARBON_REPO + File.separator + "text-files"; 41 | private static final String RUNTIME_DEPLOYER_REPO = RUNTIME_REPO + File.separator + "text-files"; 42 | private CustomDeploymentService deploymentService; 43 | private DeploymentEngine deploymentEngine; 44 | private CustomDeployer customDeployer; 45 | private String artifactPath; 46 | private String artifactPath2; 47 | 48 | 49 | /** 50 | * @param testName 51 | */ 52 | public DeploymentServiceTest(String testName) { 53 | super(testName); 54 | } 55 | 56 | @BeforeTest 57 | public void setup() throws Exception { 58 | customDeployer = new CustomDeployer(); 59 | artifactPath = getTestResourceFile(DEPLOYER_REPO).getAbsolutePath() 60 | + File.separator + "sample1.txt"; 61 | artifactPath2 = getTestResourceFile(RUNTIME_DEPLOYER_REPO).getAbsolutePath() 62 | + File.separator + "sample2.txt"; 63 | deploymentEngine = new DeploymentEngine(); 64 | deploymentEngine.start(getTestResourceFile(CARBON_REPO).getAbsolutePath(), 65 | getTestResourceFile(DEPLOYER_REPO).getAbsolutePath()); 66 | deploymentEngine.registerDeployer(customDeployer); 67 | } 68 | 69 | @Test 70 | public void testDeploymentService() { 71 | deploymentService = new CustomDeploymentService(deploymentEngine); 72 | } 73 | 74 | @Test(dependsOnMethods = {"testDeploymentService"}) 75 | public void testDeploy() throws CarbonDeploymentException { 76 | deploymentService.deploy(artifactPath, customDeployer.getArtifactType()); 77 | Assert.assertTrue(CustomDeployer.sample1Deployed); 78 | deploymentService.deploy(artifactPath2, customDeployer.getArtifactType()); 79 | Assert.assertTrue(CustomDeployer.sample2Deployed); 80 | } 81 | 82 | @Test(dependsOnMethods = {"testDeploy"}) 83 | public void testUpdate() throws CarbonDeploymentException { 84 | deploymentService.redeploy(new File(artifactPath).getName(), 85 | customDeployer.getArtifactType()); 86 | Assert.assertTrue(CustomDeployer.sample1Updated); 87 | deploymentService.redeploy(new File(artifactPath2).getName(), 88 | customDeployer.getArtifactType()); 89 | Assert.assertTrue(CustomDeployer.sample2Updated); 90 | } 91 | 92 | @Test(dependsOnMethods = {"testUpdate"}) 93 | public void testUndeploy() throws CarbonDeploymentException { 94 | deploymentService.undeploy(new File(artifactPath).getName(), 95 | customDeployer.getArtifactType()); 96 | Assert.assertFalse(CustomDeployer.sample1Deployed); 97 | deploymentService.undeploy(new File(artifactPath2).getName(), 98 | customDeployer.getArtifactType()); 99 | Assert.assertFalse(CustomDeployer.sample2Deployed); 100 | } 101 | 102 | @AfterTest 103 | public void cleanupTempfile() throws IOException { 104 | FileUtils.deleteDir(new File(getTestResourceFile(CARBON_REPO).getAbsolutePath() + 105 | File.separator + "file:text-files")); 106 | FileUtils.deleteDir(new File(getTestResourceFile(RUNTIME_REPO).getAbsolutePath() + 107 | File.separator + "file:text-files")); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /features/org.wso2.carbon.deployment.engine.feature/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | org.wso2.carbon.deployment 21 | org.wso2.carbon.deployment.parent 22 | 5.1.8-SNAPSHOT 23 | ../../pom.xml 24 | 25 | 26 | 4.0.0 27 | org.wso2.carbon.deployment.engine.feature 28 | 5.1.8-SNAPSHOT 29 | carbon-feature 30 | 31 | WSO2 Carbon Deployment Engine - Feature 32 | http://wso2.org 33 | This feature contains the core bundles required by the Deployment feature 34 | 35 | 36 | 37 | org.wso2.carbon.deployment 38 | org.wso2.carbon.deployment.engine 39 | 40 | 41 | 42 | 43 | 44 | 45 | resources 46 | 47 | 48 | src/main/resources 49 | 50 | 51 | ${project.build.directory}/docs/ 52 | 53 | 54 | 55 | 56 | org.apache.maven.plugins 57 | maven-dependency-plugin 58 | 59 | 60 | unpack 61 | package 62 | 63 | unpack 64 | 65 | 66 | 67 | 68 | org.wso2.carbon.deployment 69 | org.wso2.carbon.deployment.engine 70 | ${carbon.deployment.version} 71 | bundle 72 | true 73 | ${project.build.directory}/docs 74 | config-docs/** 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.wso2.carbon.maven 83 | carbon-feature-plugin 84 | true 85 | 86 | 87 | 1-p2-feature-generation 88 | 89 | generate 90 | 91 | 92 | ../etc/feature.properties 93 | 94 | 95 | org.wso2.carbon.p2.category.type 96 | server 97 | 98 | 99 | org.eclipse.equinox.p2.type.group 100 | false 101 | 102 | 103 | 104 | 105 | org.wso2.carbon.deployment.engine 106 | ${carbon.deployment.version} 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/main/java/org/wso2/carbon/deployment/notifier/internal/DeploymentNotifierListenerComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.notifier.internal; 17 | 18 | import org.osgi.framework.BundleContext; 19 | import org.osgi.service.component.annotations.Activate; 20 | import org.osgi.service.component.annotations.Component; 21 | import org.osgi.service.component.annotations.Deactivate; 22 | import org.osgi.service.component.annotations.Reference; 23 | import org.osgi.service.component.annotations.ReferenceCardinality; 24 | import org.osgi.service.component.annotations.ReferencePolicy; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | import org.wso2.carbon.config.provider.ConfigProvider; 28 | import org.wso2.carbon.deployment.engine.LifecycleListener; 29 | import org.wso2.carbon.deployment.notifier.DeploymentNotifierLifecycleListener; 30 | import org.wso2.carbon.kernel.CarbonRuntime; 31 | 32 | /** 33 | * This service component is responsible for initializing the DeploymentEngine and listening for deployer registrations. 34 | * 35 | * @since 5.0.0 36 | */ 37 | @Component( 38 | name = "DeploymentNotifierListenerComponent", 39 | immediate = true 40 | ) 41 | @SuppressWarnings("unused") 42 | public class DeploymentNotifierListenerComponent { 43 | private static final Logger logger = LoggerFactory.getLogger(DeploymentNotifierListenerComponent.class); 44 | 45 | /** 46 | * This is the activation method of DeploymentNotifierListenerComponent. This will be called when its references are 47 | * satisfied. 48 | * 49 | * @param bundleContext the bundle context instance of the carbon core bundle used service registration, etc. 50 | * @throws Exception this will be thrown if an issue occurs while executing the activate method 51 | */ 52 | @Activate 53 | public void start(BundleContext bundleContext) throws Exception { 54 | LifecycleListener deploymentCoordinationLifecycleListener = new DeploymentNotifierLifecycleListener(); 55 | bundleContext.registerService(LifecycleListener.class, deploymentCoordinationLifecycleListener, null); 56 | logger.debug("Registered DeploymentNotifierLifecycleListener."); 57 | } 58 | 59 | /** 60 | * This is the deactivation method of DeploymentNotifierListenerComponent. This will be called when this component 61 | * is being stopped or references are satisfied during runtime. 62 | * 63 | * @throws Exception this will be thrown if an issue occurs while executing the de-activate method 64 | */ 65 | @Deactivate 66 | public void stop() throws Exception { 67 | } 68 | 69 | /** 70 | * Get the CarbonRuntime service. 71 | * This is the bind method that gets called for CarbonRuntime service registration that satisfy the policy. 72 | * 73 | * @param carbonRuntime the CarbonRuntime service that is registered as a service. 74 | */ 75 | @Reference( 76 | name = "carbon.runtime.service", 77 | service = CarbonRuntime.class, 78 | cardinality = ReferenceCardinality.MANDATORY, 79 | policy = ReferencePolicy.DYNAMIC, 80 | unbind = "unregisterCarbonRuntime" 81 | ) 82 | protected void registerCarbonRuntime(CarbonRuntime carbonRuntime) { 83 | DataHolder.getInstance().setCarbonRuntime(carbonRuntime); 84 | } 85 | 86 | /** 87 | * This is the unbind method for the above reference that gets called for CarbonRuntime instance un-registrations. 88 | * 89 | * @param carbonRuntime the CarbonRuntime service that get unregistered. 90 | */ 91 | protected void unregisterCarbonRuntime(CarbonRuntime carbonRuntime) { 92 | DataHolder.getInstance().setCarbonRuntime(null); 93 | } 94 | 95 | /** 96 | * Get the ConfigProvider service. 97 | * This is the bind method that gets called for ConfigProvider service registration that satisfy the policy. 98 | * 99 | * @param configProvider the ConfigProvider service that is registered as a service. 100 | */ 101 | @Reference( 102 | name = "carbon.config.provider", 103 | service = ConfigProvider.class, 104 | cardinality = ReferenceCardinality.MANDATORY, 105 | policy = ReferencePolicy.DYNAMIC, 106 | unbind = "unregisterConfigProvider" 107 | ) 108 | protected void registerConfigProvider(ConfigProvider configProvider) { 109 | DataHolder.getInstance().setConfigProvider(configProvider); 110 | } 111 | 112 | /** 113 | * This is the unbind method for the above reference that gets called for ConfigProvider instance un-registrations. 114 | * 115 | * @param configProvider the ConfigProvider service that get unregistered. 116 | */ 117 | protected void unregisterConfigProvider(ConfigProvider configProvider) { 118 | DataHolder.getInstance().setConfigProvider(null); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/Artifact.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine; 17 | 18 | import java.io.File; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | /** 23 | *

24 | * This class provide an abstraction level for the concept "artifact" in carbon. 25 | *

26 | *

27 | * An artifact can be considered as a thing to deploy in carbon. 28 | * Eg: webapp, service, jaggery-app, proxy-service, sequence, spi, endpoint 29 | *

30 | *

31 | * Each artifact is associated with a deployer, which can process and deploy it to the relevant 32 | * runtime configuration. 33 | *

34 | *

35 | * An artifact will have a unique identifier (key), which can be used for artifact identification 36 | * within a runtime. 37 | *

38 | * An artifact can have custom properties that are needed for relevant runtime environment. 39 | * 40 | * @since 5.0.0 41 | */ 42 | public class Artifact { 43 | 44 | /** 45 | * The file associated with the artifact instance. 46 | */ 47 | private File file; 48 | 49 | /** 50 | * Keeps track of the last modified time of this artifact. 51 | */ 52 | private long lastModifiedTime; 53 | 54 | /** 55 | * Version of the artifact. 56 | */ 57 | private String version; 58 | 59 | /** 60 | * A key to uniquely identify an Artifact within a runtime. 61 | */ 62 | private Object key; 63 | 64 | /** 65 | * Deployment directory that the artifact is associated with Eg : webapps, sequences, apis, etc. 66 | */ 67 | private ArtifactType type; 68 | 69 | /** 70 | * To keep set of custom properties related to this artifact. 71 | */ 72 | private Map properties = new HashMap<>(); 73 | 74 | /** 75 | * Default constructor which takes the associated file with this artifact instance. 76 | * 77 | * @param file the associated file 78 | */ 79 | public Artifact(File file) { 80 | this.file = file; 81 | } 82 | 83 | /** 84 | * Returns a meaningful name for this artifact. 85 | * 86 | * @return file name 87 | */ 88 | public String getName() { 89 | return file.getName(); 90 | } 91 | 92 | /** 93 | * A key is used to uniquely identify an Artifact within a runtime. 94 | * 95 | * @return key 96 | */ 97 | public Object getKey() { 98 | return key; 99 | } 100 | 101 | /** 102 | * Sets a given key to this artifact instance. 103 | * 104 | * @param key key 105 | */ 106 | public void setKey(Object key) { 107 | this.key = key; 108 | } 109 | 110 | /** 111 | * Path of the file associated with this artifact. 112 | * 113 | * @return path 114 | */ 115 | public String getPath() { 116 | return file.getPath(); 117 | } 118 | 119 | /** 120 | * The file associated with the artifact. 121 | * 122 | * @return file 123 | */ 124 | public File getFile() { 125 | return file; 126 | } 127 | 128 | /** 129 | * Version of the artifact. 130 | * 131 | * @return version 132 | */ 133 | public String getVersion() { 134 | return version; 135 | } 136 | 137 | /** 138 | * Sets a given version to this artifact instance. 139 | * 140 | * @param version version to be set 141 | */ 142 | public void setVersion(String version) { 143 | this.version = version; 144 | } 145 | 146 | /** 147 | * ArtifactType of the artifact. 148 | * Eg : war, aar, dbs 149 | * 150 | * @return artifact directory 151 | */ 152 | public ArtifactType getType() { 153 | return type; 154 | } 155 | 156 | /** 157 | * Sets the given directory for this artifact instance. 158 | * 159 | * @param type directory of the artifact to be set 160 | */ 161 | public void setType(ArtifactType type) { 162 | this.type = type; 163 | } 164 | 165 | /** 166 | * This will return the last modified time of this artifact. 167 | * 168 | * @return last modified time 169 | */ 170 | public long getLastModifiedTime() { 171 | return lastModifiedTime; 172 | } 173 | 174 | /** 175 | * Sets the last modified time of this artifact. 176 | * 177 | * @param lastModifiedTime lastModifiedTime 178 | */ 179 | public void setLastModifiedTime(long lastModifiedTime) { 180 | this.lastModifiedTime = lastModifiedTime; 181 | } 182 | 183 | /** 184 | * This will return the Map of custom properties for this artifact. 185 | * 186 | * @return custom properties map 187 | */ 188 | public Map getProperties() { 189 | return this.properties; 190 | } 191 | 192 | /** 193 | * This method allows to set custom properties which are needed for this Artifact. 194 | * 195 | * @param properties map of custom properties 196 | */ 197 | public void setProperties(Map properties) { 198 | this.properties = properties; 199 | } 200 | 201 | } 202 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/main/java/org/wso2/carbon/deployment/engine/internal/CarbonDeploymentService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.internal; 17 | 18 | import org.wso2.carbon.deployment.engine.Artifact; 19 | import org.wso2.carbon.deployment.engine.ArtifactType; 20 | import org.wso2.carbon.deployment.engine.Deployer; 21 | import org.wso2.carbon.deployment.engine.DeploymentService; 22 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 23 | import org.wso2.carbon.utils.FileUtils; 24 | import org.wso2.carbon.utils.Utils; 25 | 26 | import java.io.File; 27 | import java.io.IOException; 28 | import java.nio.file.Path; 29 | import java.nio.file.Paths; 30 | 31 | /** 32 | * This class represent the implementation of deployment, undeployment and redeployment of Carbon Artifacts. 33 | * 34 | * @since 5.0.0 35 | */ 36 | public class CarbonDeploymentService implements DeploymentService { 37 | 38 | private DeploymentEngine carbonDeploymentEngine; 39 | 40 | /** 41 | * This will construct the CarbonDeploymentService using the given DeploymentEngine instance. 42 | * 43 | * @param carbonDeploymentEngine the DeploymentEngine instance used with constructing the CarbonDeploymentService 44 | */ 45 | public CarbonDeploymentService(DeploymentEngine carbonDeploymentEngine) { 46 | this.carbonDeploymentEngine = carbonDeploymentEngine; 47 | } 48 | 49 | /** 50 | * This method will be called externally to deploy an artifact by giving the artifact deployment 51 | * directory and the path. The consumers of the DeploymentService will be calling this method. 52 | * 53 | * @param artifactPath path where the artifact resides. This has to be the full qualified path 54 | * of the artifact 55 | * @param artifactType the type of the artifact going to be dpeloyed 56 | * Eg : webapp, dataservice, sequence 57 | * @throws CarbonDeploymentException this will be thrown on error situation while trying deploy the given artifact 58 | */ 59 | public void deploy(String artifactPath, ArtifactType artifactType) 60 | throws CarbonDeploymentException { 61 | Utils.checkSecurity(); 62 | Deployer deployer = carbonDeploymentEngine.getDeployer(artifactType); 63 | if (deployer == null) { 64 | throw new CarbonDeploymentException("Unknown artifactType : " + artifactType); 65 | } 66 | try { 67 | Path destination = Paths.get(carbonDeploymentEngine.getServerRepositoryDirectory().getAbsolutePath(), 68 | deployer.getLocation().getFile()); 69 | FileUtils.copyFileToDir(new File(artifactPath), destination.toFile()); 70 | } catch (IOException e) { 71 | throw new CarbonDeploymentException("Error wile copying artifact", e); 72 | } 73 | } 74 | 75 | /** 76 | * This method will be called externally to undeploy an artifact by giving the artifact deployment 77 | * directory and the path. The consumers of the DeploymentService will be calling this method. 78 | * 79 | * @param key artifact key to uniquely identify an artifact in a runtime 80 | * Eg: for webapps this can be webapp context such as /foo , /bar, etc 81 | * for service this can be service name such as EchoService, VersionService, etc 82 | * @param artifactType the type of the artifact going to be deployed 83 | * Eg : webapp, dataservice, sequence 84 | * @throws CarbonDeploymentException this will be thrown on error situation while trying undeploy the given artifact 85 | */ 86 | public void undeploy(Object key, ArtifactType artifactType) throws CarbonDeploymentException { 87 | Utils.checkSecurity(); 88 | Deployer deployer = carbonDeploymentEngine.getDeployer(artifactType); 89 | if (deployer == null) { 90 | throw new CarbonDeploymentException("Unknown artifactType : " + artifactType); 91 | } 92 | 93 | Artifact deployedArtifact = carbonDeploymentEngine.getDeployedArtifact(artifactType, key); 94 | if (deployedArtifact != null) { 95 | FileUtils.deleteDir(new File(deployedArtifact.getPath())); 96 | } else { 97 | throw new CarbonDeploymentException("Cannot find artifact with key : " + key + 98 | " to undeploy"); 99 | } 100 | } 101 | 102 | /** 103 | * This method is same as deploy and undeploy, will be called externally to undeploy an artifact by giving 104 | * the artifact deployment directory and the path. The consumers of the DeploymentService will be calling 105 | * this method. 106 | * 107 | * @param key artifact key to uniquely identify an artifact in a runtime 108 | * Eg: for webapps this can be webapp context such as /foo , /bar, etc 109 | * for service this can be service name such as EchoService, VersionService, etc 110 | * @param artifactType the type of the artifact going to be deployed 111 | * Eg : webapp, dataservice, sequence 112 | * @throws CarbonDeploymentException throws redeployment exceptions 113 | */ 114 | public void redeploy(Object key, ArtifactType artifactType) throws CarbonDeploymentException { 115 | // TODO implement this 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/src/test/java/org/wso2/carbon/deployment/engine/deployers/CustomDeployer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.deployers; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | import org.wso2.carbon.deployment.engine.Artifact; 21 | import org.wso2.carbon.deployment.engine.ArtifactType; 22 | import org.wso2.carbon.deployment.engine.Deployer; 23 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 24 | 25 | import java.io.File; 26 | import java.io.FileInputStream; 27 | import java.io.IOException; 28 | import java.net.MalformedURLException; 29 | import java.net.URL; 30 | 31 | /** 32 | * Custom Deployer class to test deployment. 33 | * 34 | * @since 5.0.0 35 | */ 36 | public class CustomDeployer implements Deployer { 37 | private static final Logger logger = LoggerFactory.getLogger(CustomDeployer.class); 38 | /** 39 | * Has init() been called?. 40 | */ 41 | public static boolean initCalled; 42 | /** 43 | * Set to true if "XML1" has been deployed. 44 | */ 45 | public static boolean sample1Deployed; 46 | /** 47 | * Set to true if "XML2" has been deployed. 48 | */ 49 | public static boolean sample2Deployed; 50 | /** 51 | * Set to true if "XML1" has been updated. 52 | */ 53 | public static boolean sample1Updated; 54 | /** 55 | * Set to true if "XML2" has been updated. 56 | */ 57 | public static boolean sample2Updated; 58 | 59 | private String directory = "text-files"; 60 | private URL directoryLocation; 61 | private ArtifactType artifactType; 62 | private String testDir = "src" + File.separator + "test" + File.separator + "resources" + 63 | File.separator + "carbon-repo" + File.separator + directory; 64 | private String testDir2 = "src" + File.separator + "test" + File.separator + "resources" + 65 | File.separator + "deployment" + File.separator + directory; 66 | 67 | public CustomDeployer() { 68 | artifactType = new ArtifactType("txt"); 69 | try { 70 | directoryLocation = new URL("file:text-files"); 71 | } catch (MalformedURLException e) { 72 | logger.error("Error while initializing directoryLocation", e); 73 | } 74 | } 75 | 76 | public void init() { 77 | logger.info("Initializing Deployer"); 78 | initCalled = true; 79 | } 80 | 81 | public String deploy(Artifact artifact) throws CarbonDeploymentException { 82 | logger.info("Deploying : " + artifact.getName()); 83 | String key = null; 84 | try (FileInputStream fis = new FileInputStream(artifact.getFile())) { 85 | int x = fis.available(); 86 | byte b[] = new byte[x]; 87 | fis.read(b); 88 | String content = new String(b); 89 | if (content.contains("sample1")) { 90 | sample1Deployed = true; 91 | key = artifact.getName(); 92 | } else if (content.contains("sample2")) { 93 | sample2Deployed = true; 94 | key = artifact.getName(); 95 | } 96 | } catch (IOException e) { 97 | throw new CarbonDeploymentException("Error while deploying : " + artifact.getName(), e); 98 | } 99 | return key; 100 | } 101 | 102 | public void undeploy(Object key) throws CarbonDeploymentException { 103 | if (!(key instanceof String)) { 104 | throw new CarbonDeploymentException("Error while Un Deploying : " + key + 105 | "is not a String value"); 106 | } 107 | logger.info("Undeploying : " + key); 108 | File fileToUndeploy; 109 | if ("sample1.txt".equals(key)) { 110 | fileToUndeploy = new File(testDir + File.separator + key); 111 | } else if ("sample2.txt".equals(key)) { 112 | fileToUndeploy = new File(testDir2 + File.separator + key); 113 | } else { 114 | throw new CarbonDeploymentException("Error while Un Deploying : " + key); 115 | } 116 | logger.info("File to undeploy : " + fileToUndeploy.getAbsolutePath()); 117 | try (FileInputStream fis = new FileInputStream(fileToUndeploy)) { 118 | int x = fis.available(); 119 | byte b[] = new byte[x]; 120 | fis.read(b); 121 | String content = new String(b); 122 | if (content.contains("sample1")) { 123 | sample1Deployed = false; 124 | } else if (content.contains("sample2")) { 125 | sample2Deployed = false; 126 | } 127 | } catch (IOException e) { 128 | throw new CarbonDeploymentException("Error while Un Deploying : " + key, e); 129 | } 130 | } 131 | 132 | public String update(Artifact artifact) throws CarbonDeploymentException { 133 | logger.info("Updating : " + artifact.getName()); 134 | try (FileInputStream fis = new FileInputStream(artifact.getFile())) { 135 | int x = fis.available(); 136 | byte b[] = new byte[x]; 137 | fis.read(b); 138 | String content = new String(b); 139 | if (content.contains("sample1")) { 140 | sample1Updated = true; 141 | } else if (content.contains("sample2")) { 142 | sample2Updated = true; 143 | } 144 | } catch (IOException e) { 145 | throw new CarbonDeploymentException("Error while updating : " + artifact.getName(), e); 146 | } 147 | return artifact.getName(); 148 | } 149 | 150 | 151 | public URL getLocation() { 152 | return directoryLocation; 153 | } 154 | 155 | public void setLocation(URL directoryLocation) { 156 | this.directoryLocation = directoryLocation; 157 | } 158 | 159 | public ArtifactType getArtifactType() { 160 | return artifactType; 161 | } 162 | 163 | public void setArtifactType(ArtifactType artifactType) { 164 | this.artifactType = artifactType; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.notifier/src/test/java/org/wso2/carbon/deployment/notifier/deployers/CustomDeployer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.notifier.deployers; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | import org.wso2.carbon.deployment.engine.Artifact; 21 | import org.wso2.carbon.deployment.engine.ArtifactType; 22 | import org.wso2.carbon.deployment.engine.Deployer; 23 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 24 | 25 | import java.io.File; 26 | import java.io.FileInputStream; 27 | import java.io.IOException; 28 | import java.net.MalformedURLException; 29 | import java.net.URL; 30 | 31 | /** 32 | * Custom Deployer class to test deployment. 33 | * 34 | * @since 5.0.0 35 | */ 36 | public class CustomDeployer implements Deployer { 37 | private static final Logger logger = LoggerFactory.getLogger(CustomDeployer.class); 38 | /** 39 | * Has init() been called?. 40 | */ 41 | public static boolean initCalled; 42 | /** 43 | * Set to true if "XML1" has been deployed. 44 | */ 45 | public static boolean sample1Deployed; 46 | /** 47 | * Set to true if "XML2" has been deployed. 48 | */ 49 | public static boolean sample2Deployed; 50 | /** 51 | * Set to true if "XML1" has been updated. 52 | */ 53 | public static boolean sample1Updated; 54 | /** 55 | * Set to true if "XML2" has been updated. 56 | */ 57 | public static boolean sample2Updated; 58 | 59 | private String directory = "text-files"; 60 | private URL directoryLocation; 61 | private ArtifactType artifactType; 62 | private String testDir = "src" + File.separator + "test" + File.separator + "resources" + 63 | File.separator + "carbon-repo" + File.separator + directory; 64 | private String testDir2 = "src" + File.separator + "test" + File.separator + "resources" + 65 | File.separator + "deployment" + File.separator + directory; 66 | 67 | public CustomDeployer() { 68 | artifactType = new ArtifactType("txt"); 69 | try { 70 | directoryLocation = new URL("file:text-files"); 71 | } catch (MalformedURLException e) { 72 | logger.error("Error while initializing directoryLocation", e); 73 | } 74 | } 75 | 76 | public void init() { 77 | logger.info("Initializing Deployer"); 78 | initCalled = true; 79 | } 80 | 81 | public String deploy(Artifact artifact) throws CarbonDeploymentException { 82 | logger.info("Deploying : " + artifact.getName()); 83 | String key = null; 84 | try { 85 | FileInputStream fis = new FileInputStream(artifact.getFile()); 86 | int x = fis.available(); 87 | byte b[] = new byte[x]; 88 | fis.read(b); 89 | String content = new String(b); 90 | if (content.contains("sample1")) { 91 | sample1Deployed = true; 92 | key = artifact.getName(); 93 | } else if (content.contains("sample2")) { 94 | sample2Deployed = true; 95 | key = artifact.getName(); 96 | } 97 | } catch (IOException e) { 98 | throw new CarbonDeploymentException("Error while deploying : " + artifact.getName(), e); 99 | } 100 | return key; 101 | } 102 | 103 | public void undeploy(Object key) throws CarbonDeploymentException { 104 | if (!(key instanceof String)) { 105 | throw new CarbonDeploymentException("Error while Un Deploying : " + key + 106 | "is not a String value"); 107 | } 108 | 109 | logger.info("Undeploying : " + key); 110 | File fileToUndeploy; 111 | if ("sample1.txt".equals(key)) { 112 | fileToUndeploy = new File(testDir + File.separator + key); 113 | } else if ("sample2.txt".equals(key)) { 114 | fileToUndeploy = new File(testDir2 + File.separator + key); 115 | } else { 116 | throw new CarbonDeploymentException("Error while Un Deploying : " + key); 117 | } 118 | logger.info("File to undeploy : " + fileToUndeploy.getAbsolutePath()); 119 | try (FileInputStream fis = new FileInputStream(fileToUndeploy)) { 120 | int x = fis.available(); 121 | byte b[] = new byte[x]; 122 | fis.read(b); 123 | String content = new String(b); 124 | if (content.contains("sample1")) { 125 | sample1Deployed = false; 126 | } else if (content.contains("sample2")) { 127 | sample2Deployed = false; 128 | } 129 | } catch (IOException e) { 130 | throw new CarbonDeploymentException("Error while Un Deploying : " + key, e); 131 | } 132 | } 133 | 134 | public String update(Artifact artifact) throws CarbonDeploymentException { 135 | logger.info("Updating : " + artifact.getName()); 136 | try (FileInputStream fis = new FileInputStream(artifact.getFile())) { 137 | int x = fis.available(); 138 | byte b[] = new byte[x]; 139 | fis.read(b); 140 | String content = new String(b); 141 | if (content.contains("sample1")) { 142 | sample1Updated = true; 143 | } else if (content.contains("sample2")) { 144 | sample2Updated = true; 145 | } 146 | } catch (IOException e) { 147 | throw new CarbonDeploymentException("Error while updating : " + artifact.getName(), e); 148 | } 149 | return artifact.getName(); 150 | } 151 | 152 | 153 | public URL getLocation() { 154 | return directoryLocation; 155 | } 156 | 157 | public void setLocation(URL directoryLocation) { 158 | this.directoryLocation = directoryLocation; 159 | } 160 | 161 | public ArtifactType getArtifactType() { 162 | return artifactType; 163 | } 164 | 165 | public void setArtifactType(ArtifactType artifactType) { 166 | this.artifactType = artifactType; 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /components/org.wso2.carbon.deployment.engine/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | org.wso2.carbon.deployment 22 | org.wso2.carbon.deployment.parent 23 | 5.1.8-SNAPSHOT 24 | ../../pom.xml 25 | 26 | 27 | 4.0.0 28 | org.wso2.carbon.deployment.engine 29 | 5.1.8-SNAPSHOT 30 | bundle 31 | WSO2 Carbon Deployment Engine 32 | 33 | The core bundle which includes the Deployment Framework 34 | 35 | http://wso2.com 36 | 37 | 38 | 39 | org.wso2.eclipse.osgi 40 | org.eclipse.osgi 41 | true 42 | 43 | 44 | org.wso2.eclipse.osgi 45 | org.eclipse.osgi.services 46 | true 47 | 48 | 49 | org.ops4j.pax.logging 50 | pax-logging-api 51 | true 52 | 53 | 54 | org.yaml 55 | snakeyaml 56 | true 57 | 58 | 59 | org.testng 60 | testng 61 | test 62 | 63 | 64 | org.jacoco 65 | org.jacoco.agent 66 | runtime 67 | test 68 | 69 | 70 | commons-io.wso2 71 | commons-io 72 | test 73 | 74 | 75 | org.wso2.carbon 76 | org.wso2.carbon.core 77 | 78 | 79 | org.wso2.carbon.utils 80 | org.wso2.carbon.utils 81 | 82 | 83 | org.wso2.carbon.config 84 | org.wso2.carbon.config 85 | 86 | 87 | org.easymock 88 | easymock 89 | test 90 | 91 | 92 | 93 | 94 | 95 | 96 | maven-surefire-plugin 97 | false 98 | 99 | 100 | src/test/resources/testng.xml 101 | 102 | 103 | 104 | 105 | org.apache.maven.plugins 106 | maven-source-plugin 107 | 108 | 109 | org.jacoco 110 | jacoco-maven-plugin 111 | 112 | 113 | org.apache.maven.plugins 114 | maven-javadoc-plugin 115 | 116 | 117 | attach-javadocs 118 | 119 | jar 120 | 121 | 122 | org.wso2.carbon.deployment.engine.internal 123 | -Xdoclint:none 124 | public 125 | true 126 | 127 | 128 | 129 | 130 | 131 | org.wso2.carbon.config 132 | org.wso2.carbon.config.maven.plugin 133 | 134 | 135 | 136 | create-doc 137 | 138 | compile 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | org.wso2.carbon.deployment.engine.internal.*, 147 | 148 | !org.wso2.carbon.deployment.engine.internal.*, 149 | org.wso2.carbon.deployment.engine.*;version="${carbon.deployment.pkg.export.version}", 150 | 151 | 152 | org.slf4j.*;version="${slf4j.logging.import.version.range}", 153 | org.osgi.framework.*;version="${osgi.framework.import.version.range}", 154 | org.yaml.snakeyaml.*;version="${org.snakeyaml.import.version.range}", 155 | org.wso2.carbon.kernel.*;version="${carbon.kernel.import.version.range}", 156 | org.wso2.carbon.utils.*;version="${carbon.utils.package.import.version.range}", 157 | org.wso2.carbon.config.*;version="${carbon.config.package.import.version.range}" 158 | 159 | 160 | startup.listener;componentName="carbon-deployment-service"; 161 | requiredService="org.wso2.carbon.deployment.engine.Deployer, 162 | org.wso2.carbon.deployment.engine.LifecycleListener", 163 | 164 | osgi.service;objectClass="org.wso2.carbon.deployment.engine.DeploymentService"; 165 | dependentComponentName="carbon-transport-mgt" 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /tests/osgi-tests/src/test/java/org/wso2/carbon/deployment/engine/osgi/CarbonDeploymentEngineOSGiTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.carbon.deployment.engine.osgi; 17 | 18 | import org.ops4j.pax.exam.ExamFactory; 19 | import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; 20 | import org.ops4j.pax.exam.spi.reactors.PerClass; 21 | import org.ops4j.pax.exam.testng.listener.PaxExam; 22 | import org.osgi.framework.BundleContext; 23 | import org.osgi.framework.InvalidSyntaxException; 24 | import org.osgi.framework.ServiceReference; 25 | import org.osgi.framework.ServiceRegistration; 26 | import org.testng.Assert; 27 | import org.testng.annotations.Listeners; 28 | import org.testng.annotations.Test; 29 | import org.wso2.carbon.container.CarbonContainerFactory; 30 | import org.wso2.carbon.deployment.engine.ArtifactType; 31 | import org.wso2.carbon.deployment.engine.Deployer; 32 | import org.wso2.carbon.deployment.engine.DeploymentService; 33 | import org.wso2.carbon.deployment.engine.LifecycleListener; 34 | import org.wso2.carbon.deployment.engine.exception.CarbonDeploymentException; 35 | 36 | import java.nio.file.Path; 37 | import java.nio.file.Paths; 38 | import java.util.Optional; 39 | import java.util.stream.Stream; 40 | import javax.inject.Inject; 41 | 42 | /** 43 | * Carbon Deployment Engine OSGi Test case. 44 | * 45 | * @since 5.0.0 46 | */ 47 | @Listeners(PaxExam.class) 48 | @ExamReactorStrategy(PerClass.class) 49 | @ExamFactory(CarbonContainerFactory.class) 50 | public class CarbonDeploymentEngineOSGiTest { 51 | 52 | public static final String DEPLOYMENT_YAML = "deployment.yaml"; 53 | 54 | @Inject 55 | private BundleContext bundleContext; 56 | 57 | @Inject 58 | private DeploymentService deploymentService; 59 | 60 | private static String artifactPath; 61 | 62 | static { 63 | String basedir = System.getProperty("basedir"); 64 | if (basedir == null) { 65 | basedir = Paths.get("..", "..", "..", "..").toString(); 66 | } 67 | Path testResourceDir = Paths.get(basedir, "src", "test", "resources"); 68 | artifactPath = Paths.get(testResourceDir.toString(), "deployment", "text-files", "sample1.txt").toString(); 69 | } 70 | 71 | @Test 72 | public void testRegisterDeployer() { 73 | ServiceRegistration serviceRegistration = bundleContext.registerService(Deployer.class.getName(), 74 | new CustomDeployer(), null); 75 | ServiceReference reference = bundleContext.getServiceReference(Deployer.class.getName()); 76 | Assert.assertNotNull(reference, "Custom Deployer Service Reference is null"); 77 | CustomDeployer deployer = (CustomDeployer) bundleContext.getService(reference); 78 | Assert.assertNotNull(deployer, "Custom Deployer Service is null"); 79 | serviceRegistration.unregister(); 80 | reference = bundleContext.getServiceReference(Deployer.class.getName()); 81 | Assert.assertNull(reference, "Custom Deployer Service Reference should be unregistered and null"); 82 | 83 | //register faulty deployers 84 | CustomDeployer deployer1 = new CustomDeployer(); 85 | deployer1.setArtifactType(null); 86 | bundleContext.registerService(Deployer.class.getName(), deployer1, null); 87 | 88 | CustomDeployer deployer2 = new CustomDeployer(); 89 | deployer2.setLocation(null); 90 | bundleContext.registerService(Deployer.class.getName(), deployer2, null); 91 | } 92 | 93 | @Test 94 | public void testRegisterLifecycleListener() throws InvalidSyntaxException { 95 | ServiceRegistration serviceRegistration = bundleContext.registerService(LifecycleListener.class.getName(), 96 | new CustomLifecycleListener(), null); 97 | ServiceReference[] references = bundleContext.getServiceReferences(LifecycleListener.class.getName(), null); 98 | Assert.assertNotNull(references, "The CustomLifecycleListener service reference cannot be found."); 99 | 100 | Optional reference = Stream.of(references).filter(this::isCustomLC).findFirst(); 101 | 102 | 103 | Assert.assertTrue(reference.isPresent(), "The CustomLifecycleListener is not registered."); 104 | 105 | LifecycleListener listener = (LifecycleListener) bundleContext.getService(reference.get()); 106 | Assert.assertNotNull(listener, "The CustomLifecycleListener is not registered."); 107 | 108 | serviceRegistration.unregister(); 109 | references = bundleContext.getServiceReferences(LifecycleListener.class.getName(), null); 110 | reference = Stream.of(references).filter(this::isCustomLC).findFirst(); 111 | Assert.assertFalse(reference.isPresent(), "The CustomLifecycleListener service un-registration failed."); 112 | } 113 | 114 | private boolean isCustomLC(ServiceReference serviceReference) { 115 | String listenerClass = bundleContext.getService(serviceReference).getClass().getName(); 116 | return listenerClass.equals("org.wso2.carbon.deployment.engine.osgi.CustomLifecycleListener"); 117 | } 118 | 119 | @Test(dependsOnMethods = {"testRegisterDeployer"}) 120 | public void testDeploymentService() throws CarbonDeploymentException { 121 | Assert.assertNotNull(deploymentService); 122 | CustomDeployer customDeployer = new CustomDeployer(); 123 | bundleContext.registerService(Deployer.class.getName(), customDeployer, null); 124 | bundleContext.registerService(LifecycleListener.class.getName(), new CustomLifecycleListener(), null); 125 | 126 | //undeploy 127 | try { 128 | deploymentService.undeploy(artifactPath, new ArtifactType<>("unknown")); 129 | } catch (CarbonDeploymentException e) { 130 | Assert.assertTrue(e.getMessage().contains("Unknown artifactType")); 131 | } 132 | try { 133 | deploymentService.undeploy("fake.path", customDeployer.getArtifactType()); 134 | } catch (CarbonDeploymentException e) { 135 | Assert.assertEquals(e.getMessage(), "Cannot find artifact with key : fake.path to undeploy"); 136 | } 137 | try { 138 | deploymentService.undeploy(artifactPath, customDeployer.getArtifactType()); 139 | } catch (CarbonDeploymentException e) { 140 | Assert.assertEquals(e.getMessage(), "Cannot find artifact with key : " + artifactPath + " to undeploy"); 141 | } 142 | //deploy 143 | try { 144 | deploymentService.deploy("fake.path", customDeployer.getArtifactType()); 145 | } catch (CarbonDeploymentException e) { 146 | Assert.assertTrue(e.getMessage().contains("Error wile copying artifact")); 147 | } 148 | try { 149 | deploymentService.deploy(artifactPath, new ArtifactType<>("unknown")); 150 | } catch (CarbonDeploymentException e) { 151 | Assert.assertTrue(e.getMessage().contains("Unknown artifactType")); 152 | } 153 | deploymentService.deploy(artifactPath, customDeployer.getArtifactType()); 154 | 155 | //redeploy - this does not do anything for the moment. 156 | deploymentService.redeploy(artifactPath, customDeployer.getArtifactType()); 157 | } 158 | 159 | } 160 | --------------------------------------------------------------------------------