├── .gitignore
├── components
├── org.wso2.carbon.lcm.core
│ ├── src
│ │ ├── test
│ │ │ ├── resources
│ │ │ │ ├── lcConfig.xml
│ │ │ │ ├── conf
│ │ │ │ │ └── lifecycle.yaml
│ │ │ │ ├── dbscripts
│ │ │ │ │ └── lifecycle
│ │ │ │ │ │ ├── h2
│ │ │ │ │ │ └── resource.sql
│ │ │ │ │ │ ├── mysql
│ │ │ │ │ │ └── resource.sql
│ │ │ │ │ │ ├── postgresql
│ │ │ │ │ │ └── resource.sql
│ │ │ │ │ │ └── oracle
│ │ │ │ │ │ └── resource.sql
│ │ │ │ └── resources
│ │ │ │ │ ├── lifecycle-config.xsd
│ │ │ │ │ └── lifecycles
│ │ │ │ │ ├── APILifeCycle.xml
│ │ │ │ │ └── ServiceLifeCycle.xml
│ │ │ └── java
│ │ │ │ └── org
│ │ │ │ └── wso2
│ │ │ │ └── carbon
│ │ │ │ └── lcm
│ │ │ │ ├── constants
│ │ │ │ └── TestConstants.java
│ │ │ │ ├── executors
│ │ │ │ └── SampleExecutor.java
│ │ │ │ ├── SampleAPI.java
│ │ │ │ └── LifecycleOperationsTest.java
│ │ └── main
│ │ │ └── java
│ │ │ └── org
│ │ │ └── wso2
│ │ │ └── carbon
│ │ │ └── lcm
│ │ │ └── core
│ │ │ ├── exception
│ │ │ └── LifecycleException.java
│ │ │ ├── beans
│ │ │ ├── PermissionBean.java
│ │ │ ├── AvailableTransitionBean.java
│ │ │ ├── CustomCodeBean.java
│ │ │ ├── LifecycleNode.java
│ │ │ ├── CheckItemBean.java
│ │ │ └── InputBean.java
│ │ │ ├── Executor.java
│ │ │ ├── impl
│ │ │ ├── LifecycleDataProvider.java
│ │ │ ├── LifecycleState.java
│ │ │ └── LifecycleEventManager.java
│ │ │ ├── constants
│ │ │ └── LifecycleConstants.java
│ │ │ ├── internal
│ │ │ └── LifecycleServiceComponent.java
│ │ │ ├── ManagedLifecycle.java
│ │ │ ├── util
│ │ │ └── LifecycleUtils.java
│ │ │ └── LifecycleOperationManager.java
│ └── pom.xml
└── org.wso2.carbon.lcm.sql
│ ├── src
│ └── main
│ │ └── java
│ │ └── org
│ │ └── wso2
│ │ └── carbon
│ │ └── lcm
│ │ └── sql
│ │ ├── beans
│ │ ├── LifecycleConfigBean.java
│ │ ├── LifecycleHistoryBean.java
│ │ └── LifecycleStateBean.java
│ │ ├── exception
│ │ └── LifecycleManagerDatabaseException.java
│ │ ├── config
│ │ ├── model
│ │ │ └── LifecycleConfig.java
│ │ └── LifecycleConfigBuilder.java
│ │ ├── constants
│ │ ├── Constants.java
│ │ └── SQLConstants.java
│ │ └── utils
│ │ └── LifecycleMgtDBUtil.java
│ └── pom.xml
├── features
├── org.wso2.carbon.lcm.sql.feature
│ ├── resources
│ │ ├── dbscripts
│ │ │ ├── mssql.sql
│ │ │ ├── h2.sql
│ │ │ ├── db2.sql
│ │ │ ├── mysql.sql
│ │ │ ├── postgresql.sql
│ │ │ ├── oracle.sql
│ │ │ └── oracle_rac.sql
│ │ ├── conf
│ │ │ ├── lifecycle-datasources.xml
│ │ │ └── lifecycle-config.xsd
│ │ └── p2.inf
│ └── pom.xml
├── org.wso2.carbon.lcm.core.feature
│ └── pom.xml
└── etc
│ └── feature.properties
├── issue_template.md
├── README.md
├── pull_request_template.md
├── pom.xml
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | target
3 | .classpath
4 | .settings
5 | .project
6 | *.iml
7 | *.iws
8 | *.ipr
9 | *~
10 | .idea
11 | features/org.wso2.carbon.lcm.sql.feature/resources/database/
12 | features/org.wso2.carbon.lcm.sql.feature/resources/database/WSO2LIFECYCLE_DB.mv.db
13 | features/org.wso2.carbon.lcm.sql.feature/resources/database/WSO2LIFECYCLE_DB.h2.db
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/resources/lcConfig.xml:
--------------------------------------------------------------------------------
1 |
2 | jdbc/WSO2LifecycleDB
3 |
4 | jdbc:h2:target/repository/database/WSO2LifecycleDB
5 | wso2carbon
6 | wso2carbon
7 | org.h2.Driver
8 | 50
9 | 60000
10 | 5
11 |
12 |
13 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/resources/dbscripts/mssql.sql:
--------------------------------------------------------------------------------
1 |
2 | IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[LC_DEFINITIONS]') AND TYPE IN (N'U'))
3 |
4 | CREATE TABLE LC_DEFINITIONS(
5 | LC_ID INTEGER IDENTITY(1,1),
6 | LC_NAME VARCHAR(255),
7 | LC_CONTENT VARBINARY(MAX),
8 | UNIQUE (ID),
9 | PRIMARY KEY (LC_NAME)
10 | );
11 |
12 | IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[LC_DATA]') AND TYPE IN (N'U'))
13 |
14 | CREATE TABLE LC_DATA(
15 | LC_STATE_ID VARCHAR(36) NOT NULL ,
16 | LC_DEFINITION_ID INTEGER ,
17 | LC_STATUS VARCHAR(255),
18 | UNIQUE (LC_STATE_ID),
19 | PRIMARY KEY (LC_STATE_ID),
20 | FOREIGN KEY (LC_DEFINITION_ID) REFERENCES LC_DEFINITIONS(ID) ON DELETE CASCADE
21 | );
22 |
--------------------------------------------------------------------------------
/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.lcm.core/src/test/resources/conf/lifecycle.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2017 WSO2 Inc. (http://wso2.org)
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 | # This is the main configuration file for resources.lifecycles
16 |
17 | # Enable lifecycle history
18 | enableHistory: true
19 |
20 | # JNDI name of the data source to be used by the life cycle framework.
21 | # This data source should be defined in a *-datasources.xml file in conf/datasources directory.
22 | dataSourceName: java:comp/env/jdbc/WSO2LifecycleDB
23 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/resources/dbscripts/h2.sql:
--------------------------------------------------------------------------------
1 | --- Start of lifecycle tables ---
2 |
3 | CREATE TABLE IF NOT EXISTS LC_DATA(
4 | LC_STATE_ID VARCHAR(36),
5 | LC_NAME VARCHAR(255),
6 | LC_STATUS VARCHAR(255),
7 | UNIQUE (LC_STATE_ID),
8 | PRIMARY KEY (LC_STATE_ID)
9 | );
10 |
11 | CREATE TABLE IF NOT EXISTS LC_HISTORY(
12 | LC_ID INTEGER NOT NULL AUTO_INCREMENT,
13 | LC_STATE_ID VARCHAR(36),
14 | PREVIOUS_STATE VARCHAR(255),
15 | POST_STATE VARCHAR(255),
16 | USERNAME VARCHAR(255),
17 | UPDATED_TIME TIMESTAMP,
18 | UNIQUE (LC_ID),
19 | );
20 |
21 | CREATE TABLE IF NOT EXISTS LC_CHECKLIST_DATA(
22 | LC_ID INTEGER NOT NULL AUTO_INCREMENT,
23 | LC_STATE_ID VARCHAR(36),
24 | LC_STATE VARCHAR(255),
25 | CHECKLIST_NAME VARCHAR(255),
26 | CHECKLIST_VALUE BOOLEAN DEFAULT FALSE,
27 | UNIQUE (LC_ID),
28 | FOREIGN KEY (LC_STATE_ID) REFERENCES LC_DATA(LC_STATE_ID)ON DELETE CASCADE
29 | );
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/resources/dbscripts/db2.sql:
--------------------------------------------------------------------------------
1 |
2 | CREATE TABLE LC_DATA (
3 | LC_STATE_ID VARCHAR(36) NOT NULL ,
4 | LC_NAME VARCHAR(255),
5 | LC_STATUS VARCHAR(255),
6 | UNIQUE (LC_STATE_ID),
7 | PRIMARY KEY (LC_STATE_ID)
8 | )/
9 |
10 | CREATE TABLE LC_HISTORY (
11 | LC_ID INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1),
12 | LC_STATE_ID VARCHAR(36),
13 | PREVIOUS_STATE VARCHAR(255),
14 | POST_STATE VARCHAR(255),
15 | USERNAME VARCHAR(255),
16 | UPDATED_TIME TIMESTAMP,
17 | UNIQUE (LC_ID)
18 | )/
19 |
20 | CREATE TABLE LC_CHECKLIST_DATA(
21 | LC_ID INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1),
22 | LC_STATE_ID VARCHAR(36),
23 | LC_STATE VARCHAR(255),
24 | CHECKLIST_NAME VARCHAR(255),
25 | CHECKLIST_VALUE BOOLEAN DEFAULT FALSE,
26 | UNIQUE (LC_ID),
27 | FOREIGN KEY (LC_STATE_ID) REFERENCES LC_DATA(LC_STATE_ID)ON DELETE CASCADE
28 | )/
29 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/resources/dbscripts/mysql.sql:
--------------------------------------------------------------------------------
1 |
2 | CREATE TABLE IF NOT EXISTS LC_DATA(
3 | LC_STATE_ID VARCHAR(36) NOT NULL ,
4 | LC_NAME VARCHAR(255),
5 | LC_STATUS VARCHAR(255),
6 | UNIQUE (LC_STATE_ID),
7 | PRIMARY KEY (LC_STATE_ID)
8 | )ENGINE INNODB;
9 |
10 | CREATE TABLE IF NOT EXISTS LC_HISTORY(
11 | LC_ID INTEGER NOT NULL AUTO_INCREMENT,
12 | LC_STATE_ID VARCHAR(36),
13 | PREVIOUS_STATE VARCHAR(255),
14 | POST_STATE VARCHAR(255),
15 | USERNAME VARCHAR(255),
16 | UPDATED_TIME TIMESTAMP,
17 | UNIQUE (LC_ID)
18 | )ENGINE INNODB;
19 |
20 | CREATE TABLE IF NOT EXISTS LC_CHECKLIST_DATA(
21 | LC_ID INTEGER NOT NULL AUTO_INCREMENT,
22 | LC_STATE_ID VARCHAR(36),
23 | LC_STATE VARCHAR(255),
24 | CHECKLIST_NAME VARCHAR(255),
25 | CHECKLIST_VALUE BOOLEAN DEFAULT FALSE,
26 | UNIQUE (LC_ID),
27 | FOREIGN KEY (LC_STATE_ID) REFERENCES LC_DATA(LC_STATE_ID)ON DELETE CASCADE
28 | )ENGINE INNODB;
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/resources/dbscripts/lifecycle/h2/resource.sql:
--------------------------------------------------------------------------------
1 | --- Start of lifecycle tables ---
2 |
3 | CREATE TABLE IF NOT EXISTS LC_DATA(
4 | LC_STATE_ID VARCHAR(36),
5 | LC_NAME VARCHAR(255) ,
6 | LC_STATUS VARCHAR(255),
7 | UNIQUE (LC_STATE_ID),
8 | PRIMARY KEY (LC_STATE_ID)
9 | );
10 |
11 | CREATE TABLE IF NOT EXISTS LC_HISTORY(
12 | LC_ID INTEGER NOT NULL AUTO_INCREMENT,
13 | LC_STATE_ID VARCHAR(36),
14 | PREVIOUS_STATE VARCHAR(255),
15 | POST_STATE VARCHAR(255),
16 | USERNAME VARCHAR(255),
17 | UPDATED_TIME TIMESTAMP,
18 | UNIQUE (LC_ID),
19 | );
20 |
21 | CREATE TABLE IF NOT EXISTS LC_CHECKLIST_DATA(
22 | LC_ID INTEGER NOT NULL AUTO_INCREMENT,
23 | LC_STATE_ID VARCHAR(36),
24 | LC_STATE VARCHAR(255),
25 | CHECKLIST_NAME VARCHAR(255),
26 | CHECKLIST_VALUE BOOLEAN DEFAULT FALSE,
27 | UNIQUE (LC_ID),
28 | FOREIGN KEY (LC_STATE_ID) REFERENCES LC_DATA(LC_STATE_ID)ON DELETE CASCADE
29 | );
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/resources/dbscripts/lifecycle/mysql/resource.sql:
--------------------------------------------------------------------------------
1 |
2 | CREATE TABLE IF NOT EXISTS LC_DATA(
3 | LC_STATE_ID VARCHAR(36) NOT NULL ,
4 | LC_NAME VARCHAR(255),
5 | LC_STATUS VARCHAR(255),
6 | UNIQUE (LC_STATE_ID),
7 | PRIMARY KEY (LC_STATE_ID)
8 | )ENGINE INNODB;
9 |
10 | CREATE TABLE IF NOT EXISTS LC_HISTORY(
11 | LC_ID INTEGER NOT NULL AUTO_INCREMENT,
12 | LC_STATE_ID VARCHAR(36),
13 | PREVIOUS_STATE VARCHAR(255),
14 | POST_STATE VARCHAR(255),
15 | USERNAME VARCHAR(255),
16 | UPDATED_TIME TIMESTAMP,
17 | UNIQUE (LC_ID)
18 | )ENGINE INNODB;
19 |
20 | CREATE TABLE IF NOT EXISTS LC_CHECKLIST_DATA(
21 | LC_ID INTEGER NOT NULL AUTO_INCREMENT,
22 | LC_STATE_ID VARCHAR(36),
23 | LC_STATE VARCHAR(255),
24 | CHECKLIST_NAME VARCHAR(255),
25 | CHECKLIST_VALUE BOOLEAN DEFAULT FALSE,
26 | UNIQUE (LC_ID),
27 | FOREIGN KEY (LC_STATE_ID) REFERENCES LC_DATA(LC_STATE_ID)ON DELETE CASCADE
28 | )ENGINE INNODB;
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/java/org/wso2/carbon/lcm/constants/TestConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.constants;
19 |
20 | public class TestConstants {
21 |
22 | public static final String SERVICE_LIFE_CYCLE = "ServiceLifeCycle";
23 | public static final String API_LIFE_CYCLE = "APILifeCycle";
24 | public static final String ADMIN = "admin";
25 | public static final String DEVELOPMENT = "Development";
26 | public static final String TESTING = "Testing";
27 | }
28 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/resources/dbscripts/postgresql.sql:
--------------------------------------------------------------------------------
1 |
2 | CREATE TABLE IF NOT EXISTS LC_DATA(
3 | LC_STATE_ID VARCHAR(36) NOT NULL ,
4 | LC_NAME VARCHAR(255),
5 | LC_STATUS VARCHAR(255),
6 | UNIQUE (LC_STATE_ID),
7 | PRIMARY KEY (LC_STATE_ID)
8 | );
9 |
10 | CREATE SEQUENCE LC_HISTORY_SEQUENCE START WITH 1 INCREMENT BY 1;
11 | CREATE TABLE IF NOT EXISTS LC_HISTORY(
12 | LC_ID INTEGER DEFAULT nextval('lc_history_sequence'),
13 | LC_STATE_ID VARCHAR(36),
14 | PREVIOUS_STATE VARCHAR(255),
15 | POST_STATE VARCHAR(255),
16 | USERNAME VARCHAR(255),
17 | UPDATED_TIME TIMESTAMP,
18 | UNIQUE (LC_ID)
19 | );
20 |
21 | CREATE SEQUENCE LC_CHECKLIST_DATA_SEQUENCE START WITH 1 INCREMENT BY 1;
22 | CREATE TABLE IF NOT EXISTS LC_CHECKLIST_DATA(
23 | LC_ID INTEGER DEFAULT nextval('lc_checklist_data_sequence'),
24 | LC_STATE_ID VARCHAR(36),
25 | LC_STATE VARCHAR(255),
26 | CHECKLIST_NAME VARCHAR(255),
27 | CHECKLIST_VALUE BOOLEAN DEFAULT FALSE,
28 | UNIQUE (LC_ID),
29 | FOREIGN KEY (LC_STATE_ID) REFERENCES LC_DATA(LC_STATE_ID)ON DELETE CASCADE
30 | );
31 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/resources/dbscripts/lifecycle/postgresql/resource.sql:
--------------------------------------------------------------------------------
1 |
2 | CREATE TABLE IF NOT EXISTS LC_DATA(
3 | LC_STATE_ID VARCHAR(36) NOT NULL ,
4 | LC_NAME VARCHAR(255),
5 | LC_STATUS VARCHAR(255),
6 | UNIQUE (LC_STATE_ID),
7 | PRIMARY KEY (LC_STATE_ID)
8 | );
9 |
10 | CREATE SEQUENCE LC_HISTORY_SEQUENCE START WITH 1 INCREMENT BY 1;
11 | CREATE TABLE IF NOT EXISTS LC_HISTORY(
12 | LC_ID INTEGER DEFAULT nextval('lc_history_sequence'),
13 | LC_STATE_ID VARCHAR(36),
14 | PREVIOUS_STATE VARCHAR(255),
15 | POST_STATE VARCHAR(255),
16 | USERNAME VARCHAR(255),
17 | UPDATED_TIME TIMESTAMP,
18 | UNIQUE (LC_ID)
19 | );
20 |
21 | CREATE SEQUENCE LC_CHECKLIST_DATA_SEQUENCE START WITH 1 INCREMENT BY 1;
22 | CREATE TABLE IF NOT EXISTS LC_CHECKLIST_DATA(
23 | LC_ID INTEGER DEFAULT nextval('lc_checklist_data_sequence'),
24 | LC_STATE_ID VARCHAR(36),
25 | LC_STATE VARCHAR(255),
26 | CHECKLIST_NAME VARCHAR(255),
27 | CHECKLIST_VALUE BOOLEAN DEFAULT FALSE,
28 | UNIQUE (LC_ID),
29 | FOREIGN KEY (LC_STATE_ID) REFERENCES LC_DATA(LC_STATE_ID)ON DELETE CASCADE
30 | );
31 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/resources/conf/lifecycle-datasources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader
5 |
6 |
7 |
8 |
9 |
10 | WSO2_LIFECYCLE_DB
11 | The datasource used for Lifecycle framework
12 |
13 | jdbc/WSO2LifecycleDB
14 |
15 |
16 |
17 | jdbc:h2:./database/WSO2LIFECYCLE_DB;DB_CLOSE_ON_EXIT=FALSE;MVCC=true
18 | wso2carbon
19 | wso2carbon
20 | org.h2.Driver
21 | 50
22 | 60000
23 | true
24 | SELECT 1
25 | 30000
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.sql/src/main/java/org/wso2/carbon/lcm/sql/beans/LifecycleConfigBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.sql.beans;
20 |
21 | /**
22 | * This bean class holds data related to particular life cycle configuration.
23 | */
24 | public class LifecycleConfigBean {
25 | private String lcName;
26 | private String lcContent;
27 |
28 | public String getLcName() {
29 | return lcName;
30 | }
31 |
32 | public void setLcName(String lcName) {
33 | this.lcName = lcName;
34 | }
35 |
36 | public String getLcContent() {
37 | return lcContent;
38 | }
39 |
40 | public void setLcContent(String lcContent) {
41 | this.lcContent = lcContent;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/exception/LifecycleException.java:
--------------------------------------------------------------------------------
1 | package org.wso2.carbon.lcm.core.exception;
2 |
3 | /**
4 | * The class {@code LifecycleException} and its subclasses are a form of
5 | * {@code Exception} that indicates conditions that a reasonable
6 | * life cycle management application might want to catch.
7 | **/
8 | public class LifecycleException extends Exception {
9 | private static final long serialVersionUID = 595805804854058405L;
10 |
11 | /**
12 | * Constructs a new Lifecycle Execution Exception with the specified detail message. The
13 | * cause is not initialized, and may subsequently be initialized by
14 | *
15 | * @param message the detail message. The detail message is saved for later retrieval
16 | * by the {@link #getMessage()} method.
17 | */
18 | public LifecycleException(String message) {
19 | super(message);
20 | }
21 |
22 | /**
23 | * Constructs a new Lifecycle Execution Exception with the specified detail message and
24 | * cause.
25 | *
26 | * @param message the detail message (which is saved for later retrieval
27 | * by the {@link #getMessage()} method).
28 | * @param e the cause (which is saved for later retrieval by the
29 | * {@link #getCause()} method).
30 | */
31 | public LifecycleException(String message, Throwable e) {
32 | super(message, e);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.sql/src/main/java/org/wso2/carbon/lcm/sql/exception/LifecycleManagerDatabaseException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.sql.exception;
20 |
21 | /**
22 | * The class {@code LifecycleManagerDatabaseException} and its subclasses are a form of
23 | * {@code Exception} that indicates conditions that a reasonable
24 | * life cycle management application might want to catch when performing database related operations.
25 | **/
26 | public class LifecycleManagerDatabaseException extends Exception {
27 |
28 | public LifecycleManagerDatabaseException(String msg) {
29 | super(msg);
30 | }
31 |
32 | public LifecycleManagerDatabaseException(String msg, Throwable e) {
33 | super(msg, e);
34 | }
35 |
36 | public LifecycleManagerDatabaseException(Throwable throwable) {
37 | super(throwable);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/beans/PermissionBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core.beans;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | /**
24 | * This bean holds the data related to permissions which requires to perform the lifecycle state change operations.
25 | */
26 | public class PermissionBean {
27 |
28 | private List roles;
29 | private String forTarget;
30 |
31 | public PermissionBean() {
32 | this.roles = new ArrayList();
33 | this.forTarget = "";
34 | }
35 |
36 | public String getForTarget() {
37 | return forTarget;
38 | }
39 |
40 | public void setForTarget(String forTarget) {
41 | this.forTarget = forTarget;
42 | }
43 |
44 | public List getRoles() {
45 | return roles;
46 | }
47 |
48 | public void setRoles(List roles) {
49 | this.roles = roles;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/beans/AvailableTransitionBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core.beans;
19 |
20 | /**
21 | * This bean holds the data about next available states for a particular lifecycle state which are defined in
22 | * lifecycle configuration.
23 | */
24 | public class AvailableTransitionBean {
25 |
26 | private String event;
27 | private String targetState;
28 |
29 | public AvailableTransitionBean(String event, String targetState) {
30 | this.event = event;
31 | this.targetState = targetState;
32 | }
33 |
34 | public String getEvent() {
35 | return event;
36 | }
37 |
38 | public void setEvent(String event) {
39 | this.event = event;
40 | }
41 |
42 | public String getTargetState() {
43 | return targetState;
44 | }
45 |
46 | public void setTargetState(String targetState) {
47 | this.targetState = targetState;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/beans/CustomCodeBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core.beans;
19 |
20 | /**
21 | * This bean holds the data for custom executors for a particular lifecycle state which are defined in lifecycle
22 | * configuration.
23 | */
24 | public class CustomCodeBean {
25 |
26 | private Object classObject;
27 | private String targetName;
28 | private String customMessage;
29 |
30 | public Object getClassObject() {
31 | return classObject;
32 | }
33 |
34 | public void setClassObject(Object classObject) {
35 | this.classObject = classObject;
36 | }
37 |
38 | public String getTargetName() {
39 | return targetName;
40 | }
41 |
42 | public void setTargetName(String targetName) {
43 | this.targetName = targetName;
44 | }
45 |
46 | public String getCustomMessage() {
47 | return customMessage;
48 | }
49 |
50 | public void setCustomMessage(String customMessage) {
51 | this.customMessage = customMessage;
52 | }
53 | }
54 |
55 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/resources/dbscripts/oracle.sql:
--------------------------------------------------------------------------------
1 |
2 | CREATE TABLE LC_DATA(
3 | LC_STATE_ID VARCHAR(36) NOT NULL,
4 | LC_NAME VARCHAR(255),
5 | LC_STATUS VARCHAR(255),
6 | PRIMARY KEY (LC_STATE_ID)
7 | )
8 | /
9 |
10 | CREATE TABLE LC_HISTORY(
11 | LC_ID INTEGER ,
12 | LC_STATE_ID VARCHAR(36),
13 | PREVIOUS_STATE VARCHAR(255),
14 | POST_STATE VARCHAR(255),
15 | USERNAME VARCHAR(255),
16 | UPDATED_TIME TIMESTAMP,
17 | UNIQUE (LC_ID)
18 | )
19 | /
20 | CREATE SEQUENCE LC_HISTORY_SEQUENCE START WITH 1 INCREMENT BY 1 NOCACHE
21 | /
22 | CREATE OR REPLACE TRIGGER LC_HISTORY_TRIGGER
23 | BEFORE INSERT
24 | ON LC_HISTORY
25 | REFERENCING NEW AS NEW
26 | FOR EACH ROW
27 | BEGIN
28 | SELECT LC_HISTORY_SEQUENCE.nextval INTO :NEW.LC_ID FROM dual;
29 | END;
30 | /
31 |
32 | CREATE TABLE LC_CHECKLIST_DATA(
33 | LC_ID INTEGER,
34 | LC_STATE_ID VARCHAR(36),
35 | LC_STATE VARCHAR(255),
36 | CHECKLIST_NAME VARCHAR(255),
37 | CHECKLIST_VALUE CHAR(1) DEFAULT '0',
38 | UNIQUE (LC_ID),
39 | FOREIGN KEY (LC_STATE_ID) REFERENCES LC_DATA(LC_STATE_ID)ON DELETE CASCADE
40 | )
41 | /
42 | CREATE SEQUENCE LC_CHECKLIST_DATA_SEQUENCE START WITH 1 INCREMENT BY 1 NOCACHE
43 | /
44 | CREATE OR REPLACE TRIGGER LC_CHECKLIST_DATA_TRIGGER
45 | BEFORE INSERT
46 | ON LC_CHECKLIST_DATA
47 | REFERENCING NEW AS NEW
48 | FOR EACH ROW
49 | BEGIN
50 | SELECT LC_CHECKLIST_DATA_SEQUENCE.nextval INTO :NEW.LC_ID FROM dual;
51 | END;
52 | /
53 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/beans/LifecycleNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core.beans;
19 |
20 | import java.util.LinkedList;
21 | import java.util.List;
22 |
23 | /**
24 | * This bean holds the data about next available states for a particular lifecycle state which are defined in
25 | * lifecycle configuration. This behaves as a node if we represent lifecycle config as graph.
26 | */
27 | public class LifecycleNode {
28 |
29 | String lifecycleState;
30 | List targetStates;
31 |
32 | public LifecycleNode() {
33 | this.targetStates = new LinkedList<>();
34 | }
35 |
36 | public String getLifecycleState() {
37 | return lifecycleState;
38 | }
39 |
40 | public void setLifecycleState(String lifecycleState) {
41 | this.lifecycleState = lifecycleState;
42 | }
43 |
44 | public List getTargetStates() {
45 | return targetStates;
46 | }
47 |
48 | public void setTargetStates(List targetStates) {
49 | this.targetStates = targetStates;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/resources/dbscripts/oracle_rac.sql:
--------------------------------------------------------------------------------
1 |
2 | CREATE TABLE LC_DATA(
3 | LC_STATE_ID VARCHAR(36) NOT NULL,
4 | LC_NAME VARCHAR(255),
5 | LC_STATUS VARCHAR(255),
6 | PRIMARY KEY (LC_STATE_ID)
7 | )
8 | /
9 |
10 | CREATE TABLE LC_HISTORY(
11 | LC_ID INTEGER ,
12 | LC_STATE_ID VARCHAR(36),
13 | PREVIOUS_STATE VARCHAR(255),
14 | POST_STATE VARCHAR(255),
15 | USERNAME VARCHAR(255),
16 | UPDATED_TIME TIMESTAMP,
17 | UNIQUE (LC_ID)
18 | )
19 |
20 | /
21 | CREATE SEQUENCE LC_HISTORY_SEQUENCE START WITH 1 INCREMENT BY CACHE 20 ORDER
22 | /
23 | CREATE OR REPLACE TRIGGER LC_HISTORY_TRIGGER
24 | BEFORE INSERT
25 | ON LC_HISTORY
26 | REFERENCING NEW AS NEW
27 | FOR EACH ROW
28 | BEGIN
29 | SELECT LC_HISTORY_SEQUENCE.nextval INTO :NEW.LC_ID FROM dual;
30 | END;
31 | /
32 |
33 | CREATE TABLE LC_CHECKLIST_DATA(
34 | LC_ID INTEGER,
35 | LC_STATE_ID VARCHAR(36),
36 | LC_STATE VARCHAR(255),
37 | CHECKLIST_NAME VARCHAR(255),
38 | CHECKLIST_VALUE CHAR(1) DEFAULT '0',
39 | UNIQUE (LC_ID),
40 | FOREIGN KEY (LC_STATE_ID) REFERENCES LC_DATA(LC_STATE_ID)ON DELETE CASCADE
41 | )
42 | /
43 | CREATE SEQUENCE LC_CHECKLIST_DATA_SEQUENCE START WITH 1 INCREMENT BY CACHE 20 ORDER
44 | /
45 | CREATE OR REPLACE TRIGGER LC_CHECKLIST_DATA_TRIGGER
46 | BEFORE INSERT
47 | ON LC_CHECKLIST_DATA
48 | REFERENCING NEW AS NEW
49 | FOR EACH ROW
50 | BEGIN
51 | SELECT LC_CHECKLIST_DATA_SEQUENCE.nextval INTO :NEW.LC_ID FROM dual;
52 | END;
53 | /
54 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/resources/dbscripts/lifecycle/oracle/resource.sql:
--------------------------------------------------------------------------------
1 |
2 | CREATE TABLE LC_DATA(
3 | LC_STATE_ID VARCHAR(36) NOT NULL,
4 | LC_NAME VARCHAR(255),
5 | LC_STATUS VARCHAR(255),
6 | PRIMARY KEY (LC_STATE_ID)
7 | )
8 | /
9 |
10 | CREATE TABLE LC_HISTORY(
11 | LC_ID INTEGER ,
12 | LC_STATE_ID VARCHAR(36),
13 | PREVIOUS_STATE VARCHAR(255),
14 | POST_STATE VARCHAR(255),
15 | USERNAME VARCHAR(255),
16 | UPDATED_TIME TIMESTAMP,
17 | UNIQUE (LC_ID)
18 | )
19 | /
20 | CREATE SEQUENCE LC_HISTORY_SEQUENCE START WITH 1 INCREMENT BY 1 NOCACHE
21 | /
22 | CREATE OR REPLACE TRIGGER LC_HISTORY_TRIGGER
23 | BEFORE INSERT
24 | ON LC_HISTORY
25 | REFERENCING NEW AS NEW
26 | FOR EACH ROW
27 | BEGIN
28 | SELECT LC_HISTORY_SEQUENCE.nextval INTO :NEW.LC_ID FROM dual;
29 | END;
30 | /
31 |
32 | CREATE TABLE LC_CHECKLIST_DATA(
33 | LC_ID INTEGER,
34 | LC_STATE_ID VARCHAR(36),
35 | LC_STATE VARCHAR(255),
36 | CHECKLIST_NAME VARCHAR(255),
37 | CHECKLIST_VALUE CHAR(1) DEFAULT '0',
38 | UNIQUE (LC_ID),
39 | FOREIGN KEY (LC_STATE_ID) REFERENCES LC_DATA(LC_STATE_ID)ON DELETE CASCADE
40 | )
41 | /
42 | CREATE SEQUENCE LC_CHECKLIST_DATA_SEQUENCE START WITH 1 INCREMENT BY 1 NOCACHE
43 | /
44 | CREATE OR REPLACE TRIGGER LC_CHECKLIST_DATA_TRIGGER
45 | BEFORE INSERT
46 | ON LC_CHECKLIST_DATA
47 | REFERENCING NEW AS NEW
48 | FOR EACH ROW
49 | BEGIN
50 | SELECT LC_CHECKLIST_DATA_SEQUENCE.nextval INTO :NEW.LC_ID FROM dual;
51 | END;
52 | /
53 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/resources/p2.inf:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Copyright 2017 WSO2, Inc. (http://wso2.org)
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 | metaRequirements.0.namespace = org.eclipse.equinox.p2.iu
17 | metaRequirements.0.name = org.wso2.carbon.extensions.touchpoint
18 | instructions.configure = \
19 | org.wso2.carbon.extensions.touchpoint.copy(source:${installFolder}/../lib/features/org.wso2.carbon.lcm.sql_${feature.version}/dbscripts/,target:${installFolder}/../{runtime}/dbscripts/lifecycle,overwrite:true);\
20 | org.wso2.carbon.extensions.touchpoint.copy(source:${installFolder}/../lib/features/org.wso2.carbon.lcm.sql_${feature.version}/conf/lifecycle-config.xsd/,target:${installFolder}/../{runtime}/resources/lifecycle-config.xsd,overwrite:true);\
21 | org.wso2.carbon.extensions.touchpoint.copy(source:${installFolder}/../lib/features/org.wso2.carbon.lcm.sql_${feature.version}/conf/scxml.xsd/,target:${installFolder}/../{runtime}/resources/scxml.xsd,overwrite:true);\
22 | org.wso2.carbon.extensions.touchpoint.copy(source:${installFolder}/../lib/features/org.wso2.carbon.lcm.sql_${feature.version}/database/WSO2LIFECYCLE_DB.mv.db/,target:${installFolder}/../{runtime}/database/WSO2LIFECYCLE_DB.mv.db,overwrite:true);\
23 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.sql/src/main/java/org/wso2/carbon/lcm/sql/config/model/LifecycleConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.sql.config.model;
19 |
20 | import org.wso2.carbon.config.annotation.Configuration;
21 | import org.wso2.carbon.config.annotation.Element;
22 | import org.wso2.carbon.lcm.sql.constants.Constants;
23 |
24 | /**
25 | * Configuration for Life cycles.
26 | */
27 | @Configuration (namespace = "wso2.lifecycle", description = "Life cycle Configuration")
28 | public class LifecycleConfig {
29 |
30 | @Element (description = "Enable or disable life cycle history")
31 | private boolean enableHistory = true;
32 |
33 | @Element (description = "Provide the jndi name of the lifecycle datasource")
34 | private String dataSourceName = Constants.LIFECYCLE_DATASOURCE;
35 |
36 | public boolean isEnableHistory() {
37 | return enableHistory;
38 | }
39 |
40 | public void setEnableHistory(boolean enableHistory) {
41 | this.enableHistory = enableHistory;
42 | }
43 |
44 | public String getDataSourceName() {
45 | return dataSourceName;
46 | }
47 |
48 | public void setDataSourceName(String dataSourceName) {
49 | this.dataSourceName = dataSourceName;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/java/org/wso2/carbon/lcm/executors/SampleExecutor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.executors;
20 |
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 | import org.wso2.carbon.lcm.SampleAPI;
24 | import org.wso2.carbon.lcm.core.Executor;
25 | import org.wso2.carbon.lcm.core.beans.InputBean;
26 |
27 | import java.util.HashMap;
28 | import java.util.Map;
29 |
30 | /**
31 | * This is a sample executor class runs with unit tests..
32 | */
33 | public class SampleExecutor implements Executor {
34 |
35 | private static Logger log = LoggerFactory.getLogger(SampleExecutor.class);
36 |
37 | private Map parameterMap = new HashMap();
38 |
39 | @Override
40 | public void init(Map parameterMap) {
41 | this.parameterMap = parameterMap;
42 | }
43 |
44 | @Override
45 | public void execute(Object resource, String currentState, String targetState) {
46 | SampleAPI api = (SampleAPI) resource;
47 | for (InputBean inputBean : api.getLifecycleState().getInputBeanList()) {
48 | log.info(inputBean.getName() + " : " + inputBean.getValues());
49 | }
50 | log.info("executed #####################################################");
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.sql/src/main/java/org/wso2/carbon/lcm/sql/config/LifecycleConfigBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.sql.config;
19 |
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 | import org.wso2.carbon.config.ConfigurationException;
23 | import org.wso2.carbon.config.provider.ConfigProvider;
24 | import org.wso2.carbon.lcm.sql.config.model.LifecycleConfig;
25 |
26 | /**
27 | * Build Lifecycle Configuration from the LifecycleConfig bean class.
28 | */
29 | public class LifecycleConfigBuilder {
30 |
31 | private static final Logger logger = LoggerFactory.getLogger(LifecycleConfigBuilder.class);
32 | public static final String LIFECYCLE_YAML = "lifecycle.yaml";
33 |
34 | public static LifecycleConfig getLifecycleConfig() {
35 | return lifecycleConfig;
36 | }
37 |
38 | private static LifecycleConfig lifecycleConfig;
39 |
40 | public static void build(ConfigProvider configProvider) {
41 | try {
42 | lifecycleConfig = configProvider.getConfigurationObject(LifecycleConfig.class);
43 | } catch (ConfigurationException e) {
44 | logger.error("Error loading Life cycle configuration");
45 | lifecycleConfig = new LifecycleConfig();
46 | }
47 | }
48 |
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.sql/src/main/java/org/wso2/carbon/lcm/sql/beans/LifecycleHistoryBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.sql.beans;
19 |
20 | import java.util.Date;
21 |
22 | /**
23 | * This bean class holds lifecycle data history related to particular lifecycle id.
24 | */
25 | public class LifecycleHistoryBean {
26 | private String previousState;
27 | private String postState;
28 | private String user;
29 | private Date updatedTime = new Date();
30 |
31 | public String getPreviousState() {
32 | return previousState;
33 | }
34 |
35 | public void setPreviousState(String previousState) {
36 | this.previousState = previousState;
37 | }
38 |
39 | public String getPostState() {
40 | return postState;
41 | }
42 |
43 | public void setPostState(String postState) {
44 | this.postState = postState;
45 | }
46 |
47 | public String getUser() {
48 | return user;
49 | }
50 |
51 | public void setUser(String user) {
52 | this.user = user;
53 | }
54 |
55 | public Date getUpdatedTime() {
56 | return new Date(updatedTime.getTime());
57 | }
58 |
59 | public void setUpdatedTime(Date updatedTime) {
60 | this.updatedTime = new Date(updatedTime.getTime());
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/resources/conf/lifecycle-config.xsd:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/resources/resources/lifecycle-config.xsd:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.sql/src/main/java/org/wso2/carbon/lcm/sql/beans/LifecycleStateBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.sql.beans;
20 |
21 | import java.util.Map;
22 |
23 | /**
24 | * This bean class holds data related to particular life cycle state. This is mapped with the LC_DATA table
25 | */
26 | public class LifecycleStateBean {
27 | private String stateId;
28 | private String lcName;
29 | private String previousStatus;
30 | private String postStatus;
31 | private Map checkListData;
32 |
33 | public String getStateId() {
34 | return stateId;
35 | }
36 |
37 | public void setStateId(String stateId) {
38 | this.stateId = stateId;
39 | }
40 |
41 | public String getPreviousStatus() {
42 | return previousStatus;
43 | }
44 |
45 | public void setPreviousStatus(String previousStatus) {
46 | this.previousStatus = previousStatus;
47 | }
48 |
49 | public String getPostStatus() {
50 | return postStatus;
51 | }
52 |
53 | public void setPostStatus(String postStatus) {
54 | this.postStatus = postStatus;
55 | }
56 |
57 | public String getLcName() {
58 | return lcName;
59 | }
60 |
61 | public void setLcName(String lcName) {
62 | this.lcName = lcName;
63 | }
64 |
65 | public Map getCheckListData() {
66 | return checkListData;
67 | }
68 |
69 | public void setCheckListData(Map checkListData) {
70 | this.checkListData = checkListData;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.sql/src/main/java/org/wso2/carbon/lcm/sql/constants/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.sql.constants;
20 |
21 | /**
22 | * This class contains constants which is referred when performing database operations.
23 | */
24 | public class Constants {
25 | public static final String LIFECYCLE_DATASOURCE = "java:comp/env/jdbc/WSO2LifecycleDB";
26 | public static final String LIFECYCLE_DB_NAME = "WSO2_LIFECYCLE_DB";
27 | public static final String LC_DEFINITION_TABLE_NAME = "LC_DEFINITIONS";
28 | public static final int SUPER_TENANT_ID = -1234;
29 | public static final String SUPER_TENANT_DOMAIN = "carbon.super";
30 | public static final String CARBON_HOME = "carbon.home";
31 | public static final String LIFECYCLE_LIST = "LIFECYCLE_LIST";
32 | public static final String LIFECYCLE_NAME = "LIFECYCLE_NAME";
33 | public static final String LIFECYCLE_DEFINITION_ID = "LIFECYCLE_DEFINITION_ID";
34 | public static final String LIFECYCLE_STATUS = "LIFECYCLE_STATUS";
35 | public static final String LIFECYCLE_CONTENT = "LIFECYCLE_CONTENT";
36 | public static final String TENANT_ID = "TENANT_ID";
37 | public static final String LC_ID = "LC_ID";
38 | public static final String CHECKLIST_NAME = "CHECKLIST_NAME";
39 | public static final String CHECKLIST_VALUE = "CHECKLIST_VALUE";
40 | public static final String ID = "ID";
41 | public static final String PREV_STATE = "PREV_STATE";
42 | public static final String POST_STATE = "POST_STATE";
43 | public static final String USER = "USERNAME";
44 | public static final String TIME = "UPDATE_TIME";
45 | }
46 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/beans/CheckItemBean.java:
--------------------------------------------------------------------------------
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 | package org.wso2.carbon.lcm.core.beans;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * This bean holds the data checklist items for a particular lifecycle state which are defined in lifecycle
24 | * configuration.
25 | */
26 | public class CheckItemBean {
27 |
28 | private List permissionsBeans;
29 | private String name;
30 | private List validationBeans;
31 | private List targets;
32 | private boolean value;
33 |
34 | public CheckItemBean() {
35 | this.permissionsBeans = new ArrayList();
36 | this.name = "";
37 | this.validationBeans = new ArrayList();
38 | this.targets = new ArrayList();
39 | this.value = false;
40 | }
41 |
42 | public List getTargets() {
43 | return targets;
44 | }
45 |
46 | public void setTargets(List targets) {
47 | this.targets = targets;
48 | }
49 |
50 | public List getValidationBeans() {
51 | return validationBeans;
52 | }
53 |
54 | public void setValidationBeans(List validationBeans) {
55 | this.validationBeans = validationBeans;
56 | }
57 |
58 | public List getPermissionsBeans() {
59 | return permissionsBeans;
60 | }
61 |
62 | public void setPermissionsBeans(List permissionsBeans) {
63 | this.permissionsBeans = permissionsBeans;
64 | }
65 |
66 | public String getName() {
67 | return name;
68 | }
69 |
70 | public void setName(String name) {
71 | this.name = name;
72 | }
73 |
74 | public boolean isValue() {
75 | return value;
76 | }
77 |
78 | public void setValue(boolean value) {
79 | this.value = value;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Lifecycle Management Component
2 |
3 | ---
4 | | Branch | Build Status |
5 | | :------ |:------------ |
6 | | master | [](https://wso2.org/jenkins/job/platform-builds/job/carbon-lcm/) |
7 | ---
8 |
9 | This component provides lifecycle management capability to any of the resource type which requires lifecycle capability.
10 | This will store all the data related to lifecycles in its side. Component will provide an unique id to outside to
11 | maintain tha mapping between the lifecycle data external object (For ex: API, APP, REST Service)
12 |
13 | All the operations are exposed the through the "ManagedLifecycle" interface. Any object which require lifecycle only
14 | need to implement this interface and invoke relevant operations.
15 | This interface have following methods with default implementation.
16 |
17 | * void createLifecycleEntry(String lcName, String user) throws LifecycleException
18 | * LifecycleState executeLifecycleEvent(String targetState, String user, String lcName)
19 | throws LifecycleException
20 | * void removeLifecycleEntry(String lcName) throws LifecycleException
21 | * LifecycleState checkListItemEvent(String lcName, String checkListItemName, boolean value)
22 | * LifecycleState getCurrentLifecycleState(String lcName) throws LifecycleException
23 |
24 | Following methods should be provide with implementation.
25 |
26 | * void associateLifecycle(LifecycleState lifecycleState) throws LifecycleException
27 | After adding lifecycle to object(which implements the interface) by calling "createLifecycleEntry" should set this
28 | lifecycle state object to its instance. Then they should implement the logic to persist lifecycle id which is in
29 | the lifecycle state. This id is the mapping between particular object and its lifecycle data.
30 |
31 | * void dissociateLifecycle() throws LifecycleException
32 | This method should update its the current object lifecycle state to null and implement the logic to remove the
33 | persisted lifecycle id which was implemented in "associateLifecycle" method.
34 |
35 | * String getLifecycleId(String lcName)
36 | This method should provide implementation to give the lifecycle id when lifecycle name is provided. A map can be
37 | used to maintain the mapping. This is used if one object is associated with multiple lifecycles.
38 |
39 | #### Note
40 | Please note that any of the above 3 methods should not be called from outside. The default methods in the
41 | interface only call the above 3 methods.
42 | Refer the SampleApi class for an implementation for "ManagedLifecycle" interface.
43 |
44 |
45 |
--------------------------------------------------------------------------------
/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.lcm.sql/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
22 |
23 | org.wso2.carbon.lcm
24 | carbon-lcm
25 | 1.2.1-SNAPSHOT
26 | ../../pom.xml
27 |
28 | 4.0.0
29 |
30 | org.wso2.carbon.lcm.sql
31 | bundle
32 | WSO2 Carbon - Life Cycles Database Component
33 |
34 |
35 |
36 |
37 | commons-io.wso2
38 | commons-io
39 |
40 |
41 | org.ops4j.pax.logging
42 | pax-logging-api
43 |
44 |
45 | org.wso2.carbon
46 | org.wso2.carbon.core
47 |
48 |
49 | com.google.code.findbugs
50 | annotations
51 |
52 |
53 |
54 |
55 |
56 | org.wso2.carbon.lcm.sql.*
57 |
58 |
59 | org.slf4j.*;version="${slf4j.logging.package.import.version.range}",
60 | org.apache.commons.io; version="1.2.0",
61 | javax.sql; version="0.0.0",
62 | javax.naming; version="0.0.0",
63 | org.wso2.carbon.kernel.*;version="${carbon.kernel.package.import.version.range}",
64 | org.wso2.carbon.utils.*;version="${carbon.utils.package.import.version.range}",
65 | org.wso2.carbon.config.*;version="${carbon.config.package.import.version.range}",
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/Executor.java:
--------------------------------------------------------------------------------
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 | package org.wso2.carbon.lcm.core;
18 |
19 |
20 | import org.wso2.carbon.lcm.core.exception.LifecycleException;
21 |
22 | import java.util.Map;
23 |
24 | /**
25 | * This is the interface that is used to write custom executors to resources.lifecycles
26 | * Executors are code segments that will run once a transition happens
27 | * */
28 | public interface Executor {
29 |
30 | /**
31 | * This method is called when the execution class is initialized.
32 | * All the execution classes are initialized only once.
33 | *
34 | * @param parameterMap Static parameter map given by the user. These are the parameters that have been given in the
35 | * lifecycle configuration as the parameters of the executor.
36 | *
37 | * Eg:-
38 | * {@code
39 | *
41 |
42 |
43 |
44 |
45 | * }
46 | The parameters defined here are passed to the executor using this method.
47 | * */
48 | void init(Map parameterMap);
49 |
50 | /**
51 | * This method will be called when the invoke() method of the default lifecycle implementation is called.
52 | * Execution logic should reside in this method since the default lifecycle implementation will determine
53 | * the execution output by looking at the output of this method.
54 | *
55 |
56 | * @param resource The resource in which the lifecycle state is changed.
57 | * @param currentState Current lifecycle state.
58 | * @param targetState The target lifecycle state.
59 | * @throws LifecycleException If exception occurs while running the executor.
60 | * */
61 | void execute(Object resource, String currentState, String targetState) throws LifecycleException;
62 | }
63 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/impl/LifecycleDataProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core.impl;
19 |
20 | import org.w3c.dom.Document;
21 | import org.wso2.carbon.lcm.core.beans.LifecycleNode;
22 | import org.wso2.carbon.lcm.core.exception.LifecycleException;
23 | import org.wso2.carbon.lcm.core.util.LifecycleOperationUtil;
24 | import org.wso2.carbon.lcm.core.util.LifecycleUtils;
25 | import org.wso2.carbon.lcm.sql.beans.LifecycleHistoryBean;
26 |
27 | import java.util.List;
28 |
29 | /**
30 | * This class provides data related to life cycles
31 | */
32 | public class LifecycleDataProvider {
33 |
34 |
35 | /**
36 | * This method provides set of operations performed to a particular lifecycle id.
37 | *
38 | * @param uuid Lifecycle Id which requires history.
39 | * @return {@code List} List of lifecycle history objects.
40 | * @throws LifecycleException If failed to get lifecycle history.
41 | */
42 | public static List getLifecycleHistory(String uuid) throws LifecycleException {
43 | return LifecycleOperationUtil.getLifecycleHistoryFromId(uuid);
44 | }
45 |
46 | /**
47 | * This method provides set of lifecycle ids in a particular state.
48 | *
49 | * @param state Filtering state.
50 | * @param lcName Name of the relevant lifecycle.
51 | * @return {@code List} List of lifecycle ids in the given state.
52 | * @throws LifecycleException If failed to get Ids from state.
53 | */
54 | public static List getIdsFromState(String state, String lcName) throws LifecycleException {
55 | return LifecycleOperationUtil.getLifecycleIds(state, lcName);
56 | }
57 |
58 | /**
59 | * This method is used to read lifecycle config and provide state chart as graph in order to visually represent the
60 | * lifecycle config.
61 | *
62 | * @param lcName Name of the lifecycle.
63 | * @return Lifecycle config as a graph of states.
64 | * @throws LifecycleException If failed to get lifecycle graph.
65 | */
66 | public static List getLifecycleGraph(String lcName) throws LifecycleException {
67 | Document lcContent = LifecycleUtils.getLifecycleConfiguration(lcName);
68 | return LifecycleOperationUtil.buildLifecycleGraph(lcContent);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/constants/LifecycleConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core.constants;
19 |
20 | /**
21 | * This class contains constants related to element specified in lifecycle configuration.
22 | */
23 | public class LifecycleConstants {
24 |
25 | /**
26 | * Defines name attribute
27 | */
28 | public static final String NAME = "name";
29 |
30 | /**
31 | * Defines "forEvent" attribute name
32 | */
33 | public static final String FOR_TARGET_ATTRIBUTE = "forTarget";
34 |
35 | public static final String LIFECYCLE_SCXML_ELEMENT_PATH = "//scxml";
36 |
37 | public static final String LIFECYCLE_STATE_ELEMENT_WITH_NAME_PATH = "//state[@id='";
38 |
39 | public static final String LIFECYCLE_DATA_ELEMENT_PATH = "//datamodel//data[@name='";
40 |
41 | public static final String LIFECYCLE_TRANSITION_INPUT_ATTRIBUTE = "transitionInput";
42 |
43 | public static final String LIFECYCLE_TRANSITION_EXECUTION_ATTRIBUTE = "transitionExecution";
44 |
45 | public static final String LIFECYCLE_TRANSITION_PERMISSION_ATTRIBUTE = "transitionPermission";
46 |
47 | public static final String LIFECYCLE_CHECKLIST_ITEM_ATTRIBUTE = "checkItems";
48 |
49 | public static final String LIFECYCLE_TRANSITION_ELEMENT = "//transition";
50 |
51 | public static final String LIFECYCLE_EVENT_ATTRIBUTE = "event";
52 |
53 | public static final String LIFECYCLE_TARGET_ATTRIBUTE = "target";
54 |
55 | public static final String LIFECYCLE_INITIAL_STATE_ATTRIBUTE = "initialstate";
56 |
57 | public static final String LIFECYCLE_ROLES_ATTRIBUTE = "roles";
58 |
59 | public static final String ASPECT = "aspect";
60 |
61 | public static final String STATE_TAG = "state";
62 |
63 | public static final String TRANSITION_ATTRIBUTE = "transition";
64 |
65 | public static final String TARGET_ATTRIBUTE = "target";
66 |
67 | public static final String VALUE_ATTRIBUTE = "value";
68 |
69 | public static final String ID_ATTRIBUTE = "id";
70 |
71 | public static final String CLASS_ATTRIBUTE = "class";
72 |
73 | public static final String REQUIRED = "required";
74 |
75 | public static final String LABEL = "label";
76 |
77 | public static final String PLACE_HOLDER = "placeHolder";
78 |
79 | public static final String REGEX = "regex";
80 |
81 | public static final String TOOLTIP = "tooltip";
82 |
83 | public static final String VALUES = "values";
84 | }
85 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.core.feature/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | carbon-lcm
5 | org.wso2.carbon.lcm
6 | 1.2.1-SNAPSHOT
7 | ../../pom.xml
8 |
9 | 4.0.0
10 |
11 | org.wso2.carbon.lcm.core.feature
12 | pom
13 |
14 |
15 |
16 | org.wso2.carbon.lcm
17 | org.wso2.carbon.lcm.sql
18 |
19 |
20 | org.wso2.carbon.lcm
21 | org.wso2.carbon.lcm.core
22 |
23 |
24 |
25 |
26 |
27 |
28 | org.wso2.carbon.maven
29 | carbon-feature-plugin
30 | ${carbon.feature.plugin.version}
31 | true
32 |
33 |
34 | 1-p2-feature-generation
35 | package
36 |
37 | generate
38 |
39 |
40 |
41 | ../etc/feature.properties
42 |
43 |
44 | org.wso2.carbon.p2.category.type
45 | server
46 |
47 |
48 | org.eclipse.equinox.p2.type.group
49 | false
50 |
51 |
52 |
53 |
54 | org.wso2.carbon.lcm.core
55 | ${project.parent.version}
56 |
57 |
58 |
59 |
60 | org.wso2.carbon.lcm.sql.feature
61 | ${carbon.lcm.version}
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/beans/InputBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core.beans;
19 |
20 | /**
21 | * This bean holds the data for transition inputs for a particular lifecycle state which are defined in lifecycle
22 | * configuration.
23 | */
24 | public class InputBean {
25 |
26 | private String name;
27 |
28 | private boolean isRequired;
29 |
30 | private String label;
31 |
32 | private String placeHolder;
33 |
34 | private String tooltip;
35 |
36 | private String regex;
37 |
38 | private String values;
39 |
40 | private String forTarget;
41 |
42 | public InputBean(String name, boolean isRequired, String label, String placeHolder, String tooltip, String regex,
43 | String values, String forTarget) {
44 | this.name = name;
45 | this.isRequired = isRequired;
46 | this.label = label;
47 | this.placeHolder = placeHolder;
48 | this.tooltip = tooltip;
49 | this.regex = regex;
50 | this.values = values;
51 | this.forTarget = forTarget;
52 | }
53 |
54 | public String getName() {
55 | return name;
56 | }
57 |
58 | public void setName(String name) {
59 | this.name = name;
60 | }
61 |
62 | public boolean isRequired() {
63 | return isRequired;
64 | }
65 |
66 | public void setRequired(boolean required) {
67 | isRequired = required;
68 | }
69 |
70 | public String getLabel() {
71 | return label;
72 | }
73 |
74 | public void setLabel(String label) {
75 | this.label = label;
76 | }
77 |
78 | public String getPlaceHolder() {
79 | return placeHolder;
80 | }
81 |
82 | public void setPlaceHolder(String placeHolder) {
83 | this.placeHolder = placeHolder;
84 | }
85 |
86 | public String getTooltip() {
87 | return tooltip;
88 | }
89 |
90 | public void setTooltip(String tooltip) {
91 | this.tooltip = tooltip;
92 | }
93 |
94 | public String getRegex() {
95 | return regex;
96 | }
97 |
98 | public void setRegex(String regex) {
99 | this.regex = regex;
100 | }
101 |
102 | public String getValues() {
103 | return values;
104 | }
105 |
106 | public void setValues(String values) {
107 | this.values = values;
108 | }
109 |
110 | public String getForTarget() {
111 | return forTarget;
112 | }
113 |
114 | public void setForTarget(String forTarget) {
115 | this.forTarget = forTarget;
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.sql/src/main/java/org/wso2/carbon/lcm/sql/constants/SQLConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.sql.constants;
20 |
21 | /**
22 | * This class contains all the sql queries as constants.
23 | */
24 | public class SQLConstants {
25 |
26 | public static final String DB_CHECK_SQL = "select 1 from LC_DEFINITIONS";
27 |
28 | public static final String ADD_LIFECYCLE_STATE_SQL =
29 | " INSERT INTO LC_DATA (LC_STATE_ID,LC_NAME,LC_STATUS)" + " VALUES (?,?,?)";
30 |
31 | public static final String UPDATE_LIFECYCLE_STATE_SQL = "UPDATE LC_DATA SET LC_STATUS=? WHERE LC_STATE_ID=? ";
32 |
33 | public static final String GET_LIFECYCLE_DATA_FROM_ID_SQL =
34 | "SELECT DATA.LC_NAME AS LIFECYCLE_NAME, DATA.LC_STATUS AS LIFECYCLE_STATUS FROM "
35 | + "LC_DATA DATA WHERE DATA.LC_STATE_ID=?";
36 |
37 | public static final String INSERT_LIFECYCLE_HISTORY_SQL = "INSERT INTO LC_HISTORY (LC_STATE_ID, PREVIOUS_STATE, "
38 | + "POST_STATE, USERNAME, UPDATED_TIME) VALUES (?,?,?,?,?)";
39 |
40 | public static final String REMOVE_LIFECYCLE_STATE = "DELETE FROM LC_DATA WHERE LC_STATE_ID=? ";
41 |
42 | public static final String CHECK_LIST_ITEM_EXIST = "SELECT CHECKLIST.LC_ID FROM LC_CHECKLIST_DATA CHECKLIST WHERE"
43 | + " CHECKLIST.LC_STATE_ID=? AND CHECKLIST.LC_STATE=? AND CHECKLIST.CHECKLIST_NAME=?";
44 |
45 | public static final String UPDATE_CHECK_LIST_ITEM_DATA = "UPDATE LC_CHECKLIST_DATA SET CHECKLIST_VALUE=? WHERE "
46 | + "CHECKLIST.LC_STATE_ID=? AND CHECKLIST.LC_STATE=? AND CHECKLIST.CHECKLIST_NAME=?";
47 |
48 | public static final String ADD_CHECK_LIST_ITEM_DATA = "INSERT INTO LC_CHECKLIST_DATA (LC_STATE_ID, LC_STATE, "
49 | + "CHECKLIST_NAME, CHECKLIST_VALUE) VALUES (?,?,?,?)";
50 |
51 | public static final String CLEAR_CHECK_LIST_DATA = "UPDATE LC_CHECKLIST_DATA SET CHECKLIST_VALUE=? WHERE "
52 | + "LC_STATE_ID=? AND LC_STATE=?";
53 |
54 | public static final String GET_CHECKLIST_DATA =
55 | "SELECT CHECKLIST.CHECKLIST_NAME AS CHECKLIST_NAME, CHECKLIST.CHECKLIST_VALUE AS CHECKLIST_VALUE FROM "
56 | + "LC_CHECKLIST_DATA CHECKLIST WHERE CHECKLIST.LC_STATE_ID=? AND CHECKLIST.LC_STATE=?";
57 |
58 | public static final String GET_LIFECYCLE_HISTORY_OF_UUID = "SELECT PREVIOUS_STATE AS PREV_STATE, POST_STATE AS "
59 | + "POST_STATE, USERNAME AS USER, UPDATED_TIME AS TIME FROM LC_HISTORY WHERE LC_STATE_ID=? "
60 | + "ORDER BY UPDATED_TIME ASC";
61 |
62 | public static final String GET_LIFECYCLE_IDS_IN_STATE = "SELECT LC_STATE_ID AS ID FROM LC_DATA WHERE LC_STATUS =?"
63 | + " AND LC_NAME=?";
64 |
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/java/org/wso2/carbon/lcm/SampleAPI.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm;
19 |
20 | import org.wso2.carbon.lcm.core.ManagedLifecycle;
21 | import org.wso2.carbon.lcm.core.impl.LifecycleState;
22 |
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | /**
27 | * This is a mock api class which implements ManagedLifecycle interface.
28 | */
29 | public class SampleAPI implements ManagedLifecycle {
30 |
31 | private String name;
32 | private String version;
33 | private LifecycleState lifecycleState;
34 | private Map lifecycleIdMap = new HashMap<>();
35 |
36 | public SampleAPI() {
37 | lifecycleState = new LifecycleState();
38 | }
39 |
40 | public String getName() {
41 | return name;
42 | }
43 |
44 | public void setName(String name) {
45 | this.name = name;
46 | }
47 |
48 | public String getVersion() {
49 | return version;
50 | }
51 |
52 | public void setVersion(String version) {
53 | this.version = version;
54 | }
55 |
56 | public LifecycleState getLifecycleState() {
57 | return lifecycleState;
58 | }
59 |
60 | public void setLifecycleState(LifecycleState lifecycleState) {
61 | this.lifecycleState = lifecycleState;
62 | }
63 |
64 | /*@Override
65 | public void creatLifecycleEntry(String lcName, String user) throws LifecycleException {
66 | this.lifecycleState = LifecycleOperationManager
67 | .creatLifecycleEntry(TestConstants.SERVICE_LIFE_CYCLE, TestConstants.ADMIN);
68 | }
69 |
70 | @Override
71 | public void executeLifecycleEvent(LifecycleState nextState, String uuid, String action, String user,
72 | Object resource) throws LifecycleException {
73 | this.lifecycleState = LifecycleOperationManager.executeLifecycleEvent(nextState, uuid, action, user, this);
74 | }
75 |
76 | @Override
77 | public void setCurrentLifecycleState(String uuid) throws LifecycleException {
78 | this.lifecycleState = LifecycleOperationManager.getCurrentLifecycleState(uuid);
79 | }*/
80 |
81 | @Override
82 | public void dissociateLifecycle(String lcName) {
83 | this.lifecycleState = null;
84 | // Implement logic to remove persisted lifecycle id in API side.
85 | }
86 |
87 | @Override
88 | public void associateLifecycle (LifecycleState lifecycleState) {
89 | setLifecycleState(lifecycleState);
90 | lifecycleIdMap.put(lifecycleState.getLcName(), lifecycleState.getLifecycleId());
91 | // Implement logic to persist lifecycle id in API side as well
92 | }
93 |
94 | /*@Override
95 | public String getLifecycleId(String lcName) {
96 | return lifecycleIdMap.get(lcName);
97 | }*/
98 |
99 | @Override
100 | public void setLifecycleStateInfo(LifecycleState lifecycleState) {
101 | this.lifecycleState = lifecycleState;
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/impl/LifecycleState.java:
--------------------------------------------------------------------------------
1 | package org.wso2.carbon.lcm.core.impl;
2 |
3 | import org.wso2.carbon.lcm.core.beans.AvailableTransitionBean;
4 | import org.wso2.carbon.lcm.core.beans.CheckItemBean;
5 | import org.wso2.carbon.lcm.core.beans.CustomCodeBean;
6 | import org.wso2.carbon.lcm.core.beans.InputBean;
7 | import org.wso2.carbon.lcm.core.beans.PermissionBean;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * This is life cycle state class and life cycle state related information such as
14 | * next executables and possible state changes etc should stored with this class.
15 | */
16 | public class LifecycleState {
17 |
18 | private String lcName;
19 | private String state;
20 | // Lifecycle id generated by framework which used as the reference in order to maintain mapping between
21 | // external asset types. This will be a UUID
22 | private String lifecycleId;
23 | private List checkItemBeanList;
24 | private List inputBeanList;
25 | private List customCodeBeanList;
26 | private List availableTransitionBeanList;
27 | private List permissionBeanList;
28 |
29 | public LifecycleState() {
30 | checkItemBeanList = new ArrayList<>();
31 | inputBeanList = new ArrayList<>();
32 | customCodeBeanList = new ArrayList<>();
33 | availableTransitionBeanList = new ArrayList<>();
34 | permissionBeanList = new ArrayList<>();
35 | }
36 |
37 | public String getLcName() {
38 | return lcName;
39 | }
40 |
41 | public void setLcName(String lcName) {
42 | this.lcName = lcName;
43 | }
44 |
45 | /**
46 | * @return current state of life cycle state
47 | */
48 | public String getState() {
49 | return state;
50 | }
51 |
52 | /**
53 | * @param state the state of current lifecycle state object.
54 | */
55 | public void setState(String state) {
56 | this.state = state;
57 | }
58 |
59 | public String getLifecycleId() {
60 | return lifecycleId;
61 | }
62 |
63 | public void setLifecycleId(String lifecycleId) {
64 | this.lifecycleId = lifecycleId;
65 | }
66 |
67 | public List getCheckItemBeanList() {
68 | return checkItemBeanList;
69 | }
70 |
71 | public void setCheckItemBeanList(List checkItemBeanList) {
72 | this.checkItemBeanList = checkItemBeanList;
73 | }
74 |
75 | public List getInputBeanList() {
76 | return inputBeanList;
77 | }
78 |
79 | public void setInputBeanList(List inputBeanList) {
80 | this.inputBeanList = inputBeanList;
81 | }
82 |
83 | public List getCustomCodeBeanList() {
84 | return customCodeBeanList;
85 | }
86 |
87 | public void setCustomCodeBeanList(List customCodeBeanList) {
88 | this.customCodeBeanList = customCodeBeanList;
89 | }
90 |
91 | public List getAvailableTransitionBeanList() {
92 | return availableTransitionBeanList;
93 | }
94 |
95 | public void setAvailableTransitionBeanList(List availableTransitionBeanList) {
96 | this.availableTransitionBeanList = availableTransitionBeanList;
97 | }
98 |
99 | public List getPermissionBeanList() {
100 | return permissionBeanList;
101 | }
102 |
103 | public void setPermissionBeanList(List permissionBeanList) {
104 | this.permissionBeanList = permissionBeanList;
105 | }
106 |
107 | //TODO Add allowed check items and other information should be here.
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/internal/LifecycleServiceComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core.internal;
19 |
20 | import org.osgi.service.component.annotations.Activate;
21 | import org.osgi.service.component.annotations.Component;
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.osgi.service.jndi.JNDIContextManager;
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 | import org.wso2.carbon.config.provider.ConfigProvider;
29 | import org.wso2.carbon.datasource.core.api.DataSourceService;
30 | import org.wso2.carbon.lcm.core.util.LifecycleUtils;
31 | import org.wso2.carbon.lcm.sql.config.LifecycleConfigBuilder;
32 | import org.wso2.carbon.lcm.sql.exception.LifecycleManagerDatabaseException;
33 | import org.wso2.carbon.lcm.sql.utils.LifecycleMgtDBUtil;
34 |
35 | /**
36 | * The bundle activator for lifecycle module.
37 | */
38 | @Component (
39 | name = "org.wso2.carbon.apimgt.lifecycle.manager.core",
40 | immediate = true
41 | )
42 | public class LifecycleServiceComponent {
43 |
44 | private static Logger log = LoggerFactory.getLogger(LifecycleServiceComponent.class);
45 | private ConfigProvider configProvider;
46 |
47 | @Activate
48 | public void start() {
49 | LifecycleUtils.initiateLCMap();
50 | if (log.isDebugEnabled()) {
51 | log.debug("Lifecycle service is activated.");
52 | }
53 | }
54 |
55 | @Reference (
56 | name = "org.wso2.carbon.datasource.DataSourceService",
57 | service = DataSourceService.class,
58 | cardinality = ReferenceCardinality.AT_LEAST_ONE,
59 | policy = ReferencePolicy.DYNAMIC,
60 | unbind = "unregisterDataSourceService"
61 | )
62 | protected void onDataSourceServiceReady(DataSourceService service) {
63 | //this is required to enforce a dependency on datasources
64 | }
65 |
66 | @Reference(
67 | name = "org.wso2.carbon.datasource.jndi",
68 | service = JNDIContextManager.class,
69 | cardinality = ReferenceCardinality.AT_LEAST_ONE,
70 | policy = ReferencePolicy.DYNAMIC,
71 | unbind = "onJNDIUnregister"
72 | )
73 | protected void onJNDIReady(JNDIContextManager service) {
74 | try {
75 | LifecycleConfigBuilder.build(configProvider);
76 | LifecycleMgtDBUtil.initialize();
77 |
78 |
79 | } catch (LifecycleManagerDatabaseException e) {
80 | log.error("Failed to initialize database. " + e);
81 | }
82 | }
83 |
84 | protected void onJNDIUnregister(JNDIContextManager jndiContextManager) {
85 | log.debug("Registering lifecycle data source");
86 | }
87 |
88 | protected void unregisterDataSourceService(DataSourceService dataSourceService) {
89 | log.debug("Un registering lifecycle data source");
90 | }
91 |
92 | /**
93 | * Get the ConfigProvider service.
94 | *
95 | * @param configProvider the ConfigProvider service that is registered as a service.
96 | */
97 | @Reference(
98 | name = "carbon.config.provider",
99 | service = ConfigProvider.class,
100 | cardinality = ReferenceCardinality.MANDATORY,
101 | policy = ReferencePolicy.DYNAMIC,
102 | unbind = "unregisterConfigProvider"
103 | )
104 | protected void registerConfigProvider(ConfigProvider configProvider) {
105 | this.configProvider = configProvider;
106 | }
107 |
108 | /**
109 | * This is the unbind method, which gets called for ConfigProvider instance un-registrations.
110 | *
111 | * @param configProvider the ConfigProvider service that get unregistered.
112 | */
113 | protected void unregisterConfigProvider(ConfigProvider configProvider) {
114 | this.configProvider = null;
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.sql/src/main/java/org/wso2/carbon/lcm/sql/utils/LifecycleMgtDBUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.sql.utils;
20 |
21 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
22 | import org.slf4j.Logger;
23 | import org.slf4j.LoggerFactory;
24 | import org.wso2.carbon.lcm.sql.config.LifecycleConfigBuilder;
25 | import org.wso2.carbon.lcm.sql.constants.Constants;
26 | import org.wso2.carbon.lcm.sql.exception.LifecycleManagerDatabaseException;
27 |
28 | import java.sql.Connection;
29 | import java.sql.PreparedStatement;
30 | import java.sql.ResultSet;
31 | import java.sql.SQLException;
32 | import javax.naming.Context;
33 | import javax.naming.InitialContext;
34 | import javax.naming.NamingException;
35 | import javax.sql.DataSource;
36 |
37 | /**
38 | * This utility class provide methods to handle database connection related operations.
39 | */
40 | public class LifecycleMgtDBUtil {
41 |
42 | private static final Logger log = LoggerFactory.getLogger(LifecycleMgtDBUtil.class);
43 | private static volatile DataSource dataSource = null;
44 |
45 | /**
46 | * Initializes the data source and creates lifecycle database.
47 | *
48 | * @throws LifecycleManagerDatabaseException if an error occurs while loading DB configuration
49 | */
50 | public static void initialize() throws LifecycleManagerDatabaseException {
51 |
52 | synchronized (LifecycleMgtDBUtil.class) {
53 | String dataSourceName = LifecycleConfigBuilder.getLifecycleConfig().getDataSourceName();
54 | if (dataSourceName == null) {
55 | dataSourceName = Constants.LIFECYCLE_DATASOURCE;
56 | }
57 | try {
58 | Context ctx = new InitialContext();
59 | dataSource = (DataSource) ctx.lookup(dataSourceName);
60 | } catch (NamingException e) {
61 | throw new LifecycleManagerDatabaseException(
62 | "Error while looking up the data " + "source: " + dataSourceName, e);
63 | }
64 | }
65 | }
66 |
67 | /**
68 | * Utility method to get a new database connection
69 | *
70 | * @return Connection
71 | * @throws SQLException if failed to get Connection
72 | */
73 | public static Connection getConnection() throws SQLException {
74 | if (dataSource != null) {
75 | return dataSource.getConnection();
76 | }
77 | throw new SQLException("Data source is not configured properly.");
78 | }
79 |
80 | /**
81 | * Utility method to close the connection streams.
82 | * @param preparedStatement PreparedStatement
83 | * @param connection Connection
84 | * @param resultSet ResultSet
85 | */
86 | public static void closeAllConnections(PreparedStatement preparedStatement, Connection connection,
87 | ResultSet resultSet) {
88 | closeConnection(connection);
89 | closeResultSet(resultSet);
90 | closeStatement(preparedStatement);
91 | }
92 |
93 | /**
94 | * Close Connection
95 | * @param dbConnection Connection
96 | */
97 | private static void closeConnection(Connection dbConnection) {
98 | if (dbConnection != null) {
99 | try {
100 | dbConnection.close();
101 | } catch (SQLException e) {
102 | log.warn("Database error. Could not close database connection. Continuing with " + "others. - " + e
103 | .getMessage(), e);
104 | }
105 | }
106 | }
107 |
108 | /**
109 | * Close ResultSet
110 | * @param resultSet ResultSet
111 | */
112 | private static void closeResultSet(ResultSet resultSet) {
113 | if (resultSet != null) {
114 | try {
115 | resultSet.close();
116 | } catch (SQLException e) {
117 | log.warn("Database error. Could not close ResultSet - " + e.getMessage(), e);
118 | }
119 | }
120 |
121 | }
122 |
123 | /**
124 | * Close PreparedStatement
125 | * @param preparedStatement PreparedStatement
126 | */
127 | public static void closeStatement(PreparedStatement preparedStatement) {
128 | if (preparedStatement != null) {
129 | try {
130 | preparedStatement.close();
131 | } catch (SQLException e) {
132 | log.warn("Database error. Could not close PreparedStatement. Continuing with" + " others. - " + e
133 | .getMessage(), e);
134 | }
135 | }
136 |
137 | }
138 |
139 | @SuppressFBWarnings("DM_CONVERT_CASE")
140 | public static String getConvertedAutoGeneratedColumnName(String dbProductName, String columnName) {
141 | String autoGeneratedColumnName = columnName;
142 | if ("PostgreSQL".equals(dbProductName)) {
143 | autoGeneratedColumnName = columnName.toLowerCase();
144 | if (log.isDebugEnabled()) {
145 | log.debug(
146 | "Database product name is PostgreSQL. Converting column name " + columnName + " to lowercase ("
147 | + autoGeneratedColumnName + ").");
148 | }
149 | }
150 |
151 | return autoGeneratedColumnName;
152 | }
153 |
154 | public static boolean canReturnGeneratedKeys(String dbProductName) {
155 | return !dbProductName.equals("OpenEdge RDBMS");
156 | }
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/resources/resources/lifecycles/APILifeCycle.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
38 |
39 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
61 |
62 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
80 |
81 |
83 |
84 |
86 |
87 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
105 |
106 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/ManagedLifecycle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core;
19 |
20 | import org.wso2.carbon.lcm.core.exception.LifecycleException;
21 | import org.wso2.carbon.lcm.core.impl.LifecycleState;
22 |
23 | /**
24 | * This is the base ManageLifecycle Interface. If users need to extend life cycle management
25 | * feature to any of the class they created they can implement this class and use the default implementation.
26 | */
27 |
28 | public interface ManagedLifecycle {
29 |
30 | /**
31 | * This method is used to attach a lifecycle to any eternal object (Ex: API)
32 | *
33 | * @param lcName Lc name which associates with the resource.
34 | * @param user The user who invoked the action. This will be used for auditing purposes.
35 | * @throws LifecycleException If failed to get lifecycle list.
36 | */
37 | /*default void createLifecycleEntry(String lcName, String user) throws LifecycleException {
38 | addLifecycle(LifecycleOperationManager.addLifecycle(lcName, user));
39 | }*/
40 |
41 | /**
42 | * This method need to call for each life cycle state change.
43 | *
44 | * @param targetState Required target state of the lifecycle.
45 | * @param user The user who invoked the action. This will be used for auditing
46 | * purposes.
47 | * @param lcName Lc name which associates with the resource.
48 | *
49 | * @throws LifecycleException If exception occurred while execute life cycle update.
50 | */
51 | /*default LifecycleState executeLifecycleEvent(String targetState, String user, String lcName)
52 | throws LifecycleException {
53 | return LifecycleOperationManager
54 | .executeLifecycleEvent(targetState, getCurrentLifecycleState(lcName).getLifecycleId(), user, this);
55 | }*/
56 |
57 | /**
58 | * Remove the lifecycle from the asset instance.
59 | *
60 | * @param lcName Lc name which associates with the resource.
61 | */
62 | /*default void removeLifecycleEntry(String lcName) throws LifecycleException {
63 | LifecycleOperationManager.removeLifecycle(getCurrentLifecycleState(lcName).getLifecycleId());
64 | removeLifecycle();
65 | }*/
66 |
67 | /**
68 | * This method need to call for each check list item operation.
69 | *
70 | * @param lcName Lc name which associates with the resource.
71 | * @param checkListItemName Name of the check list item as specified in the lc config.
72 | * @param value Value of the check list item. Either selected or not.
73 | *
74 | * @throws LifecycleException If exception occurred while execute life cycle update.
75 | */
76 | /*default LifecycleState checkListItemEvent(String lcName, String checkListItemName, boolean value)
77 | throws LifecycleException {
78 | return LifecycleOperationManager.checkListItemEvent(getCurrentLifecycleState(lcName).getLifecycleId(),
79 | getCurrentLifecycleState(lcName).getState(), checkListItemName, value);
80 | }*/
81 |
82 | /**
83 | * This method should be implemented to create association between object which implementing Managed Lifecycle and
84 | * the Lifecycle framework. This method should implement logic which saves the returned uuid in the external
85 | * party (API, APP etc). So both parties will have lifecycle uuid saved in their side which will cater the
86 | * purpose of mapping.
87 | *
88 | * @param lifecycleState Lifecycle state object.
89 | * @throws LifecycleException If exception occurred while associating lifecycle.
90 | */
91 | void associateLifecycle(LifecycleState lifecycleState) throws LifecycleException;
92 |
93 | /**
94 | * @param lcName Name of the lifecycle to be removed.
95 | * This method should be implemented to remove the lifecycle data from the object which implements this interface.
96 | * Persisted lifecycle state id (say stored in database) should be removed by implementing this method.
97 | * @throws LifecycleException If exception occurred while disassociating lifecycle.
98 | */
99 | void dissociateLifecycle(String lcName) throws LifecycleException;
100 |
101 | /**
102 | * @param lifecycleState Lifecycle state object.
103 | * This method should be implemented to update the lifecycle state after state change operation and check list
104 | * item operation
105 | * @throws LifecycleException If exception occurred while setting lifecycle state info.
106 | */
107 | void setLifecycleStateInfo(LifecycleState lifecycleState) throws LifecycleException;
108 |
109 | /**
110 | * This method is used to provide lifecycle state data object for a particular life cycle. "getLifecycleId"
111 | * method should provide proper implementation in order to resolve lifecycle uuid using lifecycle name.
112 | *
113 | * @param lcName Name of the lifecycle.
114 | *
115 | */
116 | /*default LifecycleState getCurrentLifecycleState(String lcName) throws LifecycleException {
117 | return LifecycleOperationManager.getCurrentLifecycleState(getLifecycleId(lcName));
118 | }*/
119 |
120 | /**
121 | * This method should provide lifecycle uuid when lifecycle name is given. Object which implements this method
122 | * should maintain a mapping between lifecycle name and uuid. This is important for multiple lifecycle as well.
123 | *
124 | * @param lcName Name of the lifecycle.
125 | *
126 | */
127 | //String getLifecycleId(String lcName);
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/resources/resources/lifecycles/ServiceLifeCycle.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/features/org.wso2.carbon.lcm.sql.feature/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
22 | carbon-lcm
23 | org.wso2.carbon.lcm
24 | 1.2.1-SNAPSHOT
25 | ../../pom.xml
26 |
27 | 4.0.0
28 |
29 | org.wso2.carbon.lcm.sql.feature
30 | pom
31 |
32 |
33 |
34 | org.wso2.carbon.lcm
35 | org.wso2.carbon.lcm.sql
36 |
37 |
38 | com.h2database
39 | h2
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.apache.maven.plugins
47 | maven-source-plugin
48 |
49 | true
50 |
51 |
52 |
53 | org.apache.maven.plugins
54 | maven-antrun-plugin
55 |
56 |
57 | clean_target
58 | install
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | run
68 |
69 |
70 |
71 | clean-lifecyel-h2-database
72 | initialize
73 |
74 | run
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | create-carbon-lifecycle-database
86 | generate-resources
87 |
88 | run
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | maven-resources-plugin
110 |
111 |
112 | prefilter-resources
113 | process-resources
114 |
115 | copy-resources
116 |
117 |
118 | src/main/resources
119 |
120 |
121 | resources
122 |
123 | conf/**
124 | dbscripts/**
125 | database/**
126 | p2.inf
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 | org.wso2.carbon.maven
136 | carbon-feature-plugin
137 | ${carbon.feature.plugin.version}
138 | true
139 |
140 |
141 | 1-p2-feature-generation
142 | package
143 |
144 | generate
145 |
146 |
147 |
148 | ../etc/feature.properties
149 |
150 |
151 | org.wso2.carbon.p2.category.type
152 | server
153 |
154 |
155 | org.eclipse.equinox.p2.type.group
156 | false
157 |
158 |
159 |
160 |
161 | org.wso2.carbon.lcm.sql
162 | ${project.parent.version}
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
22 | org.wso2.carbon.lcm
23 | carbon-lcm
24 | 1.2.1-SNAPSHOT
25 | ../../pom.xml
26 |
27 | 4.0.0
28 |
29 | org.wso2.carbon.lcm.core
30 |
31 | bundle
32 | WSO2 Carbon - Life Cycles BE
33 |
34 |
35 |
36 |
37 | org.apache.maven.plugins
38 | maven-antrun-plugin
39 |
40 |
41 | create-test-database
42 | compile
43 |
44 | run
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | org.apache.maven.plugins
67 | maven-surefire-plugin
68 | 2.12
69 |
70 |
71 |
72 | LCManagerDBConfigurationPath
73 | ${basedir}/src/test/resources/lcConfig.xml
74 |
75 |
76 | LCConfigPath
77 | ${basedir}/src/test/resources/resources.lifecycles
78 |
79 |
80 | carbon.home
81 | ${basedir}/src/test/resources/
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | org.wso2.carbon
93 | org.wso2.carbon.core
94 |
95 |
96 | org.osgi
97 | org.osgi.core
98 |
99 |
100 | org.wso2.eclipse.osgi
101 | org.eclipse.osgi.services
102 |
103 |
104 | org.wso2.carbon.lcm
105 | org.wso2.carbon.lcm.sql
106 |
107 |
108 | com.h2database.wso2
109 | h2-database-engine
110 |
111 |
112 | org.eclipse.osgi
113 | org.eclipse.osgi
114 |
115 |
116 | commons-logging
117 | commons-logging
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 | org.wso2.carbon.datasources
142 | org.wso2.carbon.datasource.core
143 |
144 |
145 |
146 | org.testng
147 | testng
148 | test
149 |
150 |
151 | org.ops4j.pax.logging
152 | pax-logging-api
153 |
154 |
155 |
156 | org.wso2.carbon.lcm.core.internal.*,
157 |
158 | !org.wso2.carbon.lcm.core.internal.*,
159 | org.wso2.carbon.lcm.core.*,
160 |
161 |
162 | org.osgi.framework.*;version="${osgi.framework.import.version.range}",
163 | org.slf4j.*;version="${slf4j.logging.package.import.version.range}",
164 | org.osgi.service.jndi; version="[1.0.0,2.0.0)",
165 | javax.xml;
166 | javax.xml.xpath; version=0.0.0,
167 | javax.xml.namespace; version=0.0.0,
168 | javax.xml.parsers; version=0.0.0,
169 | javax.xml.transform.*; version=0.0.0,
170 | org.apache.commons*; version=1.2.0,
171 | javax.xml.validation; version=0.0.0,
172 | org.w3c.dom; version=0.0.0,
173 | org.osgi.service.component; version=1.7.0
174 | javax.naming*; version=0.0.0,
175 | javax.sql; version=0.0.0,
176 | org.xml.sax; version=0.0.0,
177 | org.wso2.carbon.kernel.*;version="${carbon.kernel.package.import.version.range}",
178 | org.wso2.carbon.lcm.sql.*;version="${carbon.lcm.package.import.version.range}",
179 | org.wso2.carbon.config.*;version="${carbon.config.package.import.version.range}",
180 | org.wso2.carbon.utils.*;version="${carbon.utils.package.import.version.range}",
181 | *;
182 |
183 | *
184 |
185 |
186 |
187 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/impl/LifecycleEventManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core.impl;
20 |
21 | import org.wso2.carbon.lcm.core.exception.LifecycleException;
22 | import org.wso2.carbon.lcm.sql.beans.LifecycleHistoryBean;
23 | import org.wso2.carbon.lcm.sql.beans.LifecycleStateBean;
24 | import org.wso2.carbon.lcm.sql.dao.LifecycleMgtDAO;
25 | import org.wso2.carbon.lcm.sql.exception.LifecycleManagerDatabaseException;
26 |
27 | import java.util.List;
28 |
29 | /**
30 | * This class communicate with DAO layer to perform lifecycle operations.
31 | */
32 | public class LifecycleEventManager {
33 |
34 | /**
35 | * Associates lifecycle with an asset. Sets the initial state as the current state.
36 | *
37 | * @param lcName Name of lifecycle which asset being associated with.
38 | * @param initialState initial state provided in the scxml configuration.
39 | * @param user The user who invoked the action. This will be used for auditing purposes.
40 | * @return uuid generated for that particular asset.
41 | * @throws LifecycleException If failed associate lifecycle state.
42 | */
43 | public String associateLifecycle(String lcName, String initialState, String user) throws LifecycleException {
44 | try {
45 | return getLCMgtDAOInstance().addLifecycleState(initialState, lcName, user);
46 | } catch (LifecycleManagerDatabaseException e) {
47 | throw new LifecycleException("Error while associating lifecycle " + lcName, e);
48 | }
49 | }
50 |
51 | /**
52 | * Associates lifecycle with an asset. Sets the initial state as the current state.
53 | *
54 | * @param lcName Name of lifecycle which asset being associated with.
55 | * @param lifecycleId Lifecycle ID
56 | * @param initialState initial state provided in the scxml configuration.
57 | * @param user The user who invoked the action. This will be used for auditing purposes.
58 | * @throws LifecycleException If failed associate lifecycle state.
59 | */
60 | public void associateLifecycle(String lcName, String lifecycleId, String initialState, String user) throws
61 | LifecycleException {
62 | try {
63 | getLCMgtDAOInstance().addLifecycleState(initialState, lifecycleId, lcName, user);
64 | } catch (LifecycleManagerDatabaseException e) {
65 | throw new LifecycleException("Error while associating lifecycle " + lcName, e);
66 | }
67 | }
68 |
69 | /**
70 | * Changes the lifecycle state.
71 | *
72 | * @param currentState Current state
73 | * @param requiredState The expected state
74 | * @param id uuid of the current state which maps with the asset.
75 | * @param user The user who invoked the action. This will be used for auditing purposes.
76 | * @throws LifecycleException If failed to change lifecycle state.
77 | */
78 | public void changeLifecycleState(String currentState, String requiredState, String id, String user)
79 | throws LifecycleException {
80 | LifecycleStateBean lifecycleStateBean = new LifecycleStateBean();
81 | lifecycleStateBean.setPreviousStatus(currentState);
82 | lifecycleStateBean.setPostStatus(requiredState);
83 | lifecycleStateBean.setStateId(id);
84 | try {
85 | getLCMgtDAOInstance().changeLifecycleState(lifecycleStateBean, user);
86 | } catch (LifecycleManagerDatabaseException e) {
87 | throw new LifecycleException("Error while changing lifecycle state to " + requiredState, e);
88 | }
89 | }
90 |
91 | /**
92 | * Remove lifecycle state data from LC_DATA table
93 | *
94 | * @param uuid uuid of the state.
95 | * @throws LifecycleException If failed to remove lifecycle data.
96 | */
97 | public void removeLifecycleStateData(String uuid) throws LifecycleException {
98 | try {
99 | getLCMgtDAOInstance().removeLifecycleState(uuid);
100 | } catch (LifecycleManagerDatabaseException e) {
101 | throw new LifecycleException("Error while deleting lifecycle data for id : " + uuid);
102 | }
103 | }
104 |
105 | /**
106 | * Get data related to particular uuid from LC_DATA table
107 | *
108 | * @param uuid uuid of the state.
109 | * @return Lifecycle state data associated with the uuid.
110 | * @throws LifecycleException If failed to get lifecycle state data.
111 | */
112 | public LifecycleStateBean getLifecycleStateData(String uuid) throws LifecycleException {
113 | try {
114 | return getLCMgtDAOInstance().getLifecycleStateDataFromId(uuid);
115 | } catch (LifecycleManagerDatabaseException e) {
116 | throw new LifecycleException("Error while getting lifecycle data for id : " + uuid);
117 | }
118 | }
119 |
120 | /**
121 | * Get data related to particular uuid and state from LC_CHECKLIST_DATA table
122 | *
123 | * @param uuid uuid of the state.
124 | * @param lcState State which data is required.
125 | * @return Lifecycle state data associated with the uuid.
126 | * @throws LifecycleException If failed to get lifecycle state data.
127 | */
128 | public LifecycleStateBean getLifecycleDataFromState(String uuid, String lcState) throws LifecycleException {
129 | try {
130 | return getLCMgtDAOInstance().getLifecycleCheckListDataFromState(uuid, lcState);
131 | } catch (LifecycleManagerDatabaseException e) {
132 | throw new LifecycleException("Error while getting lifecycle data for id : " + uuid);
133 | }
134 | }
135 |
136 | public void changeCheckListItemData(String uuid, String currentState, String checkListItemName, boolean value)
137 | throws LifecycleException {
138 | try {
139 | getLCMgtDAOInstance().changeCheckListItemData(uuid, currentState, checkListItemName, value);
140 | } catch (LifecycleManagerDatabaseException e) {
141 | throw new LifecycleException("Error while adding checklist data for item " + checkListItemName, e);
142 | }
143 | }
144 |
145 | /**
146 | * This method provides set of operations performed to a particular lifecycle id.
147 | *
148 | * @param uuid Lifecycle Id which requires history.
149 | * @return List of lifecycle history objects.
150 | * @throws LifecycleException If failed to get lifecycle history from ID.
151 | */
152 | public List getLifecycleHistoryFromId(String uuid) throws LifecycleException {
153 | try {
154 | return getLCMgtDAOInstance().getLifecycleHistoryFromId(uuid);
155 | } catch (LifecycleManagerDatabaseException e) {
156 | throw new LifecycleException("Error while getting lifecycle data from uuid : " + uuid, e);
157 | }
158 | }
159 |
160 | /**
161 | * This method provides set of lifecycle ids in a particular state.
162 | *
163 | * @param state Filtering state.
164 | * @param lcName Name of the relevant lifecycle.
165 | * @return {@code List} List of lifecycle ids in the given state.
166 | * @throws LifecycleException If failed to get lifecycle Ids
167 | */
168 | public List getLifecycleIds (String state, String lcName) throws LifecycleException {
169 | try {
170 | return getLCMgtDAOInstance().getLifecycleIdsFromState(state, lcName);
171 | } catch (LifecycleManagerDatabaseException e) {
172 | throw new LifecycleException("Error while getting lifecycle ids in state : " + state, e);
173 | }
174 | }
175 |
176 | private LifecycleMgtDAO getLCMgtDAOInstance() {
177 | return LifecycleMgtDAO.getInstance();
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
22 | org.wso2
23 | wso2
24 | 5
25 |
26 | 4.0.0
27 |
28 | org.wso2.carbon.lcm
29 | carbon-lcm
30 | 1.2.1-SNAPSHOT
31 | Lifecycle Management
32 | pom
33 |
34 |
35 | https://github.com/wso2/carbon-lcm.git
36 | scm:git:https://github.com/wso2/carbon-lcm.git
37 | scm:git:https://github.com/wso2/carbon-lcm.git
38 | HEAD
39 |
40 |
41 |
42 | components/org.wso2.carbon.lcm.sql
43 | components/org.wso2.carbon.lcm.core
44 | features/org.wso2.carbon.lcm.sql.feature
45 | features/org.wso2.carbon.lcm.core.feature
46 |
47 |
48 |
49 |
50 |
51 |
52 | org.wso2.carbon.maven
53 | carbon-feature-plugin
54 | ${carbon.feature.plugin.version}
55 |
56 |
57 | org.apache.maven.plugins
58 | maven-release-plugin
59 |
60 | clean install
61 | true
62 |
63 |
64 |
65 | org.apache.maven.plugins
66 | maven-deploy-plugin
67 |
68 |
69 | org.apache.maven.plugins
70 | maven-javadoc-plugin
71 |
72 |
73 |
74 |
75 |
76 | org.apache.maven.plugins
77 | maven-compiler-plugin
78 |
79 | ${java.version}
80 | ${java.version}
81 |
82 |
83 |
84 | org.apache.maven.plugins
85 | maven-javadoc-plugin
86 |
87 |
88 | docs
89 | compile
90 |
91 | javadoc
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 | org.wso2.carbon.lcm
103 | org.wso2.carbon.lcm.sql
104 | ${carbon.lcm.version}
105 |
106 |
107 | org.wso2.carbon.lcm
108 | org.wso2.carbon.lcm.core
109 | ${carbon.lcm.version}
110 |
111 |
112 | org.wso2.carbon
113 | org.wso2.carbon.core
114 | ${carbon.kernel.version}
115 |
116 |
117 | com.h2database.wso2
118 | h2-database-engine
119 | ${com.h2database.wso2.version}
120 |
121 |
122 | commons-io.wso2
123 | commons-io
124 | ${commons-io.version}
125 |
126 |
127 | org.osgi
128 | org.osgi.core
129 | ${org.osgi.core.version}
130 |
131 |
132 | org.wso2.eclipse.osgi
133 | org.eclipse.osgi.services
134 | ${equinox.osgi.services.version}
135 |
136 |
137 | com.h2database
138 | h2
139 | ${h2.version}
140 |
141 |
142 | org.wso2.carbon.datasources
143 | org.wso2.carbon.datasource.core
144 | ${carbon.datasources.version}
145 |
146 |
147 | org.testng
148 | testng
149 | test
150 | ${testng.version}
151 |
152 |
153 | org.ops4j.pax.logging
154 | pax-logging-api
155 | ${pax.logging.api.version}
156 |
157 |
158 | com.google.code.findbugs
159 | annotations
160 | ${findbug.exclude.version}
161 |
162 |
163 | org.wso2.carbon.config
164 | org.wso2.carbon.config
165 | ${carbon.config.version}
166 |
167 |
168 |
169 |
170 |
171 | 1.2.1-SNAPSHOT
172 | [1.2.0, 2.0.0)
173 | [1.8.0, 2.0.0)
174 | [1.7.1, 2.0.0)
175 | 5.2.0
176 | [5.2.0, 6.0.0)
177 | 1.1.4
178 | 2.1.4
179 | [2.1.0, 3.0.0)
180 | 2.0.4
181 | [2.0.0, 3.0.0)
182 | 1.4.192
183 | 6.9.10
184 | 2.4.0.wso2v1
185 | 6.0.0
186 | 3.4.0.v20140312-2051
187 | 3.1.3
188 | 1.2.140.wso2v3
189 | 1.9.0
190 | 3.0.0
191 | 1.8
192 |
193 |
194 |
195 |
196 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/test/java/org/wso2/carbon/lcm/LifecycleOperationsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm;
20 |
21 | import com.zaxxer.hikari.HikariDataSource;
22 | import org.slf4j.Logger;
23 | import org.slf4j.LoggerFactory;
24 | import org.testng.annotations.BeforeClass;
25 | import org.testng.annotations.Test;
26 | import org.w3c.dom.Document;
27 | import org.wso2.carbon.config.ConfigurationException;
28 | import org.wso2.carbon.config.provider.ConfigProvider;
29 | import org.wso2.carbon.lcm.constants.TestConstants;
30 | import org.wso2.carbon.lcm.core.LifecycleOperationManager;
31 | import org.wso2.carbon.lcm.core.beans.InputBean;
32 | import org.wso2.carbon.lcm.core.beans.LifecycleNode;
33 | import org.wso2.carbon.lcm.core.exception.LifecycleException;
34 | import org.wso2.carbon.lcm.core.impl.LifecycleDataProvider;
35 | import org.wso2.carbon.lcm.core.impl.LifecycleState;
36 | import org.wso2.carbon.lcm.core.util.LifecycleUtils;
37 | import org.wso2.carbon.lcm.sql.beans.LifecycleHistoryBean;
38 | import org.wso2.carbon.lcm.sql.config.LifecycleConfigBuilder;
39 | import org.wso2.carbon.lcm.sql.config.model.LifecycleConfig;
40 | import org.wso2.carbon.lcm.sql.dao.LifecycleMgtDAO;
41 | import org.wso2.carbon.lcm.sql.utils.LifecycleMgtDBUtil;
42 | import org.xml.sax.SAXException;
43 |
44 | import java.io.File;
45 | import java.io.IOException;
46 | import java.util.Hashtable;
47 | import java.util.List;
48 | import javax.naming.Context;
49 | import javax.naming.InitialContext;
50 | import javax.naming.NamingException;
51 | import javax.naming.spi.InitialContextFactory;
52 | import javax.naming.spi.InitialContextFactoryBuilder;
53 | import javax.naming.spi.NamingManager;
54 | import javax.xml.parsers.DocumentBuilder;
55 | import javax.xml.parsers.DocumentBuilderFactory;
56 | import javax.xml.parsers.ParserConfigurationException;
57 |
58 | import static org.testng.Assert.assertEquals;
59 | import static org.testng.Assert.assertNotNull;
60 | import static org.testng.Assert.assertTrue;
61 |
62 | @Test
63 | public class LifecycleOperationsTest {
64 |
65 | public static LifecycleMgtDAO lifecycleMgtDAO;
66 | public static SampleAPI sampleAPI;
67 | private static Logger log = LoggerFactory.getLogger(LifecycleOperationsTest.class);
68 |
69 | @BeforeClass
70 | protected void setUp() throws Exception {
71 | System.setProperty("wso2.runtime.path", "src" + File.separator + "test" + File.separator + "resources");
72 | String dbConfigPath = System.getProperty("LCManagerDBConfigurationPath");
73 | setupInitialContext(dbConfigPath);
74 | LifecycleConfigBuilder.build(new ConfigProvider() {
75 |
76 | @Override public T getConfigurationObject(Class configClass) throws ConfigurationException {
77 | T lifecycleConfig = (T) new LifecycleConfig();
78 | return lifecycleConfig;
79 | }
80 |
81 | @Override
82 | public Object getConfigurationObject(String s) throws ConfigurationException {
83 | return null;
84 | }
85 | });
86 | LifecycleUtils.initiateLCMap();
87 | LifecycleMgtDBUtil.initialize();
88 | lifecycleMgtDAO = LifecycleMgtDAO.getInstance();
89 | }
90 |
91 | private static void setupInitialContext(String configFilePath) {
92 | try {
93 | NamingManager.setInitialContextFactoryBuilder(new InitialContextFactoryBuilder() {
94 |
95 | @Override public InitialContextFactory createInitialContextFactory(Hashtable, ?> environment)
96 | throws NamingException {
97 | return new InitialContextFactory() {
98 |
99 | @Override public Context getInitialContext(Hashtable, ?> environment) throws NamingException {
100 | return new InitialContext() {
101 |
102 | private Hashtable dataSources = new Hashtable<>();
103 |
104 | @Override public Object lookup(String name) throws NamingException {
105 |
106 | if (dataSources.isEmpty()) { //init datasources
107 | try {
108 | File fXmlFile = new File(configFilePath);
109 | DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
110 | DocumentBuilder dBuilder = null;
111 | dBuilder = dbFactory.newDocumentBuilder();
112 | Document doc = null;
113 | doc = dBuilder.parse(fXmlFile);
114 |
115 | String databaseURL = doc.getElementsByTagName("URL").item(0)
116 | .getTextContent();
117 | String databaseUser = doc.getElementsByTagName("Username").item(0)
118 | .getTextContent();
119 | String databasePass = doc.getElementsByTagName("Password").item(0)
120 | .getTextContent();
121 | String databaseDriver = doc.getElementsByTagName("Driver").item(0)
122 | .getTextContent();
123 |
124 | HikariDataSource basicDataSource = new HikariDataSource();
125 | basicDataSource.setDriverClassName(databaseDriver);
126 | basicDataSource.setJdbcUrl(databaseURL);
127 | basicDataSource.setUsername(databaseUser);
128 | basicDataSource.setPassword(databasePass);
129 | dataSources.put("java:comp/env/jdbc/WSO2LifecycleDB", basicDataSource);
130 | } catch (IOException | ParserConfigurationException | SAXException e) {
131 | log.error("Error while setting datasource properties.", e);
132 | }
133 |
134 | //add more datasources to the list as necessary
135 | }
136 |
137 | if (dataSources.containsKey(name)) {
138 | return dataSources.get(name);
139 | }
140 |
141 | throw new NamingException("Unable to find datasource: " + name);
142 | }
143 | };
144 | }
145 |
146 | };
147 | }
148 |
149 | });
150 | } catch (NamingException e) {
151 | log.error("Error while setting initial context" + e);
152 | }
153 | }
154 |
155 | @Test
156 | public void testAssociateLifecycle() throws Exception {
157 | sampleAPI = createSampleAPI();
158 |
159 | sampleAPI.associateLifecycle(
160 | LifecycleOperationManager.addLifecycle(TestConstants.SERVICE_LIFE_CYCLE, TestConstants.ADMIN));
161 | assertNotNull(sampleAPI.getLifecycleState().getState());
162 | assertNotNull(sampleAPI.getLifecycleState().getLifecycleId());
163 | }
164 |
165 | @Test(dependsOnMethods = "testAssociateLifecycle")
166 | public void testValidTargetStateProvided() throws Exception {
167 | LifecycleState currentState = sampleAPI.getLifecycleState();
168 | String uuid = currentState.getLifecycleId();
169 | String targetState = "Production";
170 | try {
171 | sampleAPI.setLifecycleState(
172 | LifecycleOperationManager.executeLifecycleEvent(targetState, uuid, TestConstants.ADMIN, sampleAPI));
173 | } catch (LifecycleException e) {
174 | assertTrue(e.getMessage()
175 | .contains("The specified target state " + targetState + " is not a valid target " + "state"));
176 | }
177 |
178 | }
179 |
180 | @Test (dependsOnMethods = { "testAssociateLifecycle", "testValidTargetStateProvided" })
181 | public void testChangeLifecycleState() throws Exception {
182 | LifecycleState currentState = sampleAPI.getLifecycleState();
183 | String uuid = currentState.getLifecycleId();
184 | String targetState = currentState.getAvailableTransitionBeanList().get(0).getTargetState();
185 | // Lets set custom input values as well
186 | for (InputBean inputBean : currentState.getInputBeanList()) {
187 | inputBean.setValues("value 1");
188 | }
189 | try {
190 | sampleAPI.setLifecycleState(
191 | LifecycleOperationManager.executeLifecycleEvent(targetState, uuid, TestConstants.ADMIN, sampleAPI));
192 | } catch (LifecycleException e) {
193 | assertTrue(e.getMessage().contains("Required checklist items are not selected"));
194 | }
195 | sampleAPI.setLifecycleState(LifecycleOperationManager
196 | .checkListItemEvent(uuid, sampleAPI.getLifecycleState().getState(), "Code Completed", true));
197 | sampleAPI.setLifecycleState(
198 | LifecycleOperationManager.executeLifecycleEvent(targetState, uuid, TestConstants.ADMIN, sampleAPI));
199 | assertEquals(sampleAPI.getLifecycleState().getState(), targetState);
200 |
201 | }
202 |
203 | @Test(dependsOnMethods = "testChangeLifecycleState")
204 | public void testGettingLifecycleHistory () throws Exception {
205 | String uuid = sampleAPI.getLifecycleState().getLifecycleId();
206 | List lifecycleHistoryBeanList = LifecycleDataProvider.getLifecycleHistory(uuid);
207 | assertTrue(lifecycleHistoryBeanList.size() == 2);
208 | assertTrue(TestConstants.DEVELOPMENT.equals(lifecycleHistoryBeanList.get(0).getPostState()));
209 | assertTrue(TestConstants.TESTING.equals(lifecycleHistoryBeanList.get(1).getPostState()));
210 | }
211 |
212 | @Test(dependsOnMethods = "testChangeLifecycleState")
213 | public void testGetLifecycleIdsFromState() throws Exception {
214 | List stateList = LifecycleDataProvider
215 | .getIdsFromState(TestConstants.TESTING, TestConstants.SERVICE_LIFE_CYCLE);
216 | assertTrue(stateList.size() == 1);
217 | }
218 |
219 | @Test(dependsOnMethods = "testGetLifecycleIdsFromState")
220 | public void testDissociateLifecycle() throws Exception {
221 | LifecycleOperationManager.removeLifecycle(sampleAPI.getLifecycleState().getLifecycleId());
222 | try {
223 | LifecycleOperationManager.getCurrentLifecycleState(sampleAPI.getLifecycleState().getLifecycleId());
224 | } catch (LifecycleException e) {
225 | assertTrue(e.getMessage().contains("Error while getting lifecycle data for id"));
226 | }
227 | }
228 |
229 | @Test
230 | public void testGetLifecycleGraph() throws Exception {
231 | List graph = LifecycleDataProvider.getLifecycleGraph(TestConstants.API_LIFE_CYCLE);
232 | assertTrue(graph.size() == 6);
233 | }
234 |
235 | private SampleAPI createSampleAPI() {
236 | SampleAPI sampleAPI = new SampleAPI();
237 | sampleAPI.setName("API 1");
238 | sampleAPI.setVersion("1.0.0");
239 | return sampleAPI;
240 | }
241 |
242 | }
243 |
--------------------------------------------------------------------------------
/features/etc/feature.properties:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Copyright (c) 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 |
20 | providerName=WSO2 Inc.
21 |
22 | ########################## license properties ##################################
23 | licenseURL=http://www.apache.org/licenses/LICENSE-2.0
24 |
25 | license=\
26 | Apache License\n\
27 | Version 2.0, January 2004\n\
28 | http://www.apache.org/licenses/\n\
29 | \n\
30 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\
31 | \n\
32 | 1. Definitions.\n\
33 | \n\
34 | "License" shall mean the terms and conditions for use, reproduction,\n\
35 | and distribution as defined by Sections 1 through 9 of this document.\n\
36 | \n\
37 | "Licensor" shall mean the copyright owner or entity authorized by\n\
38 | the copyright owner that is granting the License.\n\
39 | \n\
40 | "Legal Entity" shall mean the union of the acting entity and all\n\
41 | other entities that control, are controlled by, or are under common\n\
42 | control with that entity. For the purposes of this definition,\n\
43 | "control" means (i) the power, direct or indirect, to cause the\n\
44 | direction or management of such entity, whether by contract or\n\
45 | otherwise, or (ii) ownership of fifty percent (50%) or more of the\n\
46 | outstanding shares, or (iii) beneficial ownership of such entity.\n\
47 | \n\
48 | "You" (or "Your") shall mean an individual or Legal Entity\n\
49 | exercising permissions granted by this License.\n\
50 | \n\
51 | "Source" form shall mean the preferred form for making modifications,\n\
52 | including but not limited to software source code, documentation\n\
53 | source, and configuration files.\n\
54 | \n\
55 | "Object" form shall mean any form resulting from mechanical\n\
56 | transformation or translation of a Source form, including but\n\
57 | not limited to compiled object code, generated documentation,\n\
58 | and conversions to other media types.\n\
59 | \n\
60 | "Work" shall mean the work of authorship, whether in Source or\n\
61 | Object form, made available under the License, as indicated by a\n\
62 | copyright notice that is included in or attached to the work\n\
63 | (an example is provided in the Appendix below).\n\
64 | \n\
65 | "Derivative Works" shall mean any work, whether in Source or Object\n\
66 | form, that is based on (or derived from) the Work and for which the\n\
67 | editorial revisions, annotations, elaborations, or other modifications\n\
68 | represent, as a whole, an original work of authorship. For the purposes\n\
69 | of this License, Derivative Works shall not include works that remain\n\
70 | separable from, or merely link (or bind by name) to the interfaces of,\n\
71 | the Work and Derivative Works thereof.\n\
72 | \n\
73 | "Contribution" shall mean any work of authorship, including\n\
74 | the original version of the Work and any modifications or additions\n\
75 | to that Work or Derivative Works thereof, that is intentionally\n\
76 | submitted to Licensor for inclusion in the Work by the copyright owner\n\
77 | or by an individual or Legal Entity authorized to submit on behalf of\n\
78 | the copyright owner. For the purposes of this definition, "submitted"\n\
79 | means any form of electronic, verbal, or written communication sent\n\
80 | to the Licensor or its representatives, including but not limited to\n\
81 | communication on electronic mailing lists, source code control systems,\n\
82 | and issue tracking systems that are managed by, or on behalf of, the\n\
83 | Licensor for the purpose of discussing and improving the Work, but\n\
84 | excluding communication that is conspicuously marked or otherwise\n\
85 | designated in writing by the copyright owner as "Not a Contribution."\n\
86 | \n\
87 | "Contributor" shall mean Licensor and any individual or Legal Entity\n\
88 | on behalf of whom a Contribution has been received by Licensor and\n\
89 | subsequently incorporated within the Work.\n\
90 | \n\
91 | 2. Grant of Copyright License. Subject to the terms and conditions of\n\
92 | this License, each Contributor hereby grants to You a perpetual,\n\
93 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n\
94 | copyright license to reproduce, prepare Derivative Works of,\n\
95 | publicly display, publicly perform, sublicense, and distribute the\n\
96 | Work and such Derivative Works in Source or Object form.\n\
97 | \n\
98 | 3. Grant of Patent License. Subject to the terms and conditions of\n\
99 | this License, each Contributor hereby grants to You a perpetual,\n\
100 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n\
101 | (except as stated in this section) patent license to make, have made,\n\
102 | use, offer to sell, sell, import, and otherwise transfer the Work,\n\
103 | where such license applies only to those patent claims licensable\n\
104 | by such Contributor that are necessarily infringed by their\n\
105 | Contribution(s) alone or by combination of their Contribution(s)\n\
106 | with the Work to which such Contribution(s) was submitted. If You\n\
107 | institute patent litigation against any entity (including a\n\
108 | cross-claim or counterclaim in a lawsuit) alleging that the Work\n\
109 | or a Contribution incorporated within the Work constitutes direct\n\
110 | or contributory patent infringement, then any patent licenses\n\
111 | granted to You under this License for that Work shall terminate\n\
112 | as of the date such litigation is filed.\n\
113 | \n\
114 | 4. Redistribution. You may reproduce and distribute copies of the\n\
115 | Work or Derivative Works thereof in any medium, with or without\n\
116 | modifications, and in Source or Object form, provided that You\n\
117 | meet the following conditions:\n\
118 | \n\
119 | (a) You must give any other recipients of the Work or\n\
120 | Derivative Works a copy of this License; and\n\
121 | \n\
122 | (b) You must cause any modified files to carry prominent notices\n\
123 | stating that You changed the files; and\n\
124 | \n\
125 | (c) You must retain, in the Source form of any Derivative Works\n\
126 | that You distribute, all copyright, patent, trademark, and\n\
127 | attribution notices from the Source form of the Work,\n\
128 | excluding those notices that do not pertain to any part of\n\
129 | the Derivative Works; and\n\
130 | \n\
131 | (d) If the Work includes a "NOTICE" text file as part of its\n\
132 | distribution, then any Derivative Works that You distribute must\n\
133 | include a readable copy of the attribution notices contained\n\
134 | within such NOTICE file, excluding those notices that do not\n\
135 | pertain to any part of the Derivative Works, in at least one\n\
136 | of the following places: within a NOTICE text file distributed\n\
137 | as part of the Derivative Works; within the Source form or\n\
138 | documentation, if provided along with the Derivative Works; or,\n\
139 | within a display generated by the Derivative Works, if and\n\
140 | wherever such third-party notices normally appear. The contents\n\
141 | of the NOTICE file are for informational purposes only and\n\
142 | do not modify the License. You may add Your own attribution\n\
143 | notices within Derivative Works that You distribute, alongside\n\
144 | or as an addendum to the NOTICE text from the Work, provided\n\
145 | that such additional attribution notices cannot be construed\n\
146 | as modifying the License.\n\
147 | \n\
148 | You may add Your own copyright statement to Your modifications and\n\
149 | may provide additional or different license terms and conditions\n\
150 | for use, reproduction, or distribution of Your modifications, or\n\
151 | for any such Derivative Works as a whole, provided Your use,\n\
152 | reproduction, and distribution of the Work otherwise complies with\n\
153 | the conditions stated in this License.\n\
154 | \n\
155 | 5. Submission of Contributions. Unless You explicitly state otherwise,\n\
156 | any Contribution intentionally submitted for inclusion in the Work\n\
157 | by You to the Licensor shall be under the terms and conditions of\n\
158 | this License, without any additional terms or conditions.\n\
159 | Notwithstanding the above, nothing herein shall supersede or modify\n\
160 | the terms of any separate license agreement you may have executed\n\
161 | with Licensor regarding such Contributions.\n\
162 | \n\
163 | 6. Trademarks. This License does not grant permission to use the trade\n\
164 | names, trademarks, service marks, or product names of the Licensor,\n\
165 | except as required for reasonable and customary use in describing the\n\
166 | origin of the Work and reproducing the content of the NOTICE file.\n\
167 | \n\
168 | 7. Disclaimer of Warranty. Unless required by applicable law or\n\
169 | agreed to in writing, Licensor provides the Work (and each\n\
170 | Contributor provides its Contributions) on an "AS IS" BASIS,\n\
171 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n\
172 | implied, including, without limitation, any warranties or conditions\n\
173 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n\
174 | PARTICULAR PURPOSE. You are solely responsible for determining the\n\
175 | appropriateness of using or redistributing the Work and assume any\n\
176 | risks associated with Your exercise of permissions under this License.\n\
177 | \n\
178 | 8. Limitation of Liability. In no event and under no legal theory,\n\
179 | whether in tort (including negligence), contract, or otherwise,\n\
180 | unless required by applicable law (such as deliberate and grossly\n\
181 | negligent acts) or agreed to in writing, shall any Contributor be\n\
182 | liable to You for damages, including any direct, indirect, special,\n\
183 | incidental, or consequential damages of any character arising as a\n\
184 | result of this License or out of the use or inability to use the\n\
185 | Work (including but not limited to damages for loss of goodwill,\n\
186 | work stoppage, computer failure or malfunction, or any and all\n\
187 | other commercial damages or losses), even if such Contributor\n\
188 | has been advised of the possibility of such damages.\n\
189 | \n\
190 | 9. Accepting Warranty or Additional Liability. While redistributing\n\
191 | the Work or Derivative Works thereof, You may choose to offer,\n\
192 | and charge a fee for, acceptance of support, warranty, indemnity,\n\
193 | or other liability obligations and/or rights consistent with this\n\
194 | License. However, in accepting such obligations, You may act only\n\
195 | on Your own behalf and on Your sole responsibility, not on behalf\n\
196 | of any other Contributor, and only if You agree to indemnify,\n\
197 | defend, and hold each Contributor harmless for any liability\n\
198 | incurred by, or claims asserted against, such Contributor by reason\n\
199 | of your accepting any such warranty or additional liability.\n\
200 | \n\
201 | END OF TERMS AND CONDITIONS\n\
202 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/util/LifecycleUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017, 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.lcm.core.util;
19 |
20 | import org.apache.commons.io.FileUtils;
21 | import org.apache.commons.io.FilenameUtils;
22 | import org.slf4j.Logger;
23 | import org.slf4j.LoggerFactory;
24 | import org.w3c.dom.Attr;
25 | import org.w3c.dom.Document;
26 | import org.w3c.dom.Element;
27 | import org.w3c.dom.Node;
28 | import org.w3c.dom.NodeList;
29 | import org.wso2.carbon.lcm.core.constants.LifecycleConstants;
30 | import org.wso2.carbon.lcm.core.exception.LifecycleException;
31 | import org.wso2.carbon.utils.Utils;
32 | import org.xml.sax.SAXException;
33 |
34 | import java.io.ByteArrayInputStream;
35 | import java.io.File;
36 | import java.io.FilenameFilter;
37 | import java.io.IOException;
38 | import java.io.InputStream;
39 | import java.io.UnsupportedEncodingException;
40 | import java.nio.charset.StandardCharsets;
41 | import java.util.ArrayList;
42 | import java.util.List;
43 | import java.util.Map;
44 | import java.util.concurrent.ConcurrentHashMap;
45 | import javax.xml.XMLConstants;
46 | import javax.xml.parsers.DocumentBuilderFactory;
47 | import javax.xml.parsers.ParserConfigurationException;
48 | import javax.xml.transform.Source;
49 | import javax.xml.transform.stream.StreamSource;
50 | import javax.xml.validation.Schema;
51 | import javax.xml.validation.SchemaFactory;
52 | import javax.xml.validation.Validator;
53 | import javax.xml.xpath.XPath;
54 | import javax.xml.xpath.XPathConstants;
55 | import javax.xml.xpath.XPathExpression;
56 | import javax.xml.xpath.XPathExpressionException;
57 | import javax.xml.xpath.XPathFactory;
58 |
59 | /**
60 | * This utility class provides methods to perform CRUD operations for lifecycle configurations.
61 | */
62 | public class LifecycleUtils {
63 |
64 | private static final Logger log = LoggerFactory.getLogger(LifecycleUtils.class);
65 | private static Map lifecycleMap;
66 | private static Validator lifecycleSchemaValidator;
67 |
68 | /**
69 | * Get the lifecycle configuration with a particular name.
70 | *
71 | * @param lcName Name of the lifecycle.
72 | * @return Lifecycle configuration.
73 | * @throws LifecycleException If failed to get lifecycle configurations.
74 | */
75 | public static Document getLifecycleConfiguration(String lcName) throws LifecycleException {
76 | if (lifecycleMap != null && lifecycleMap.containsKey(lcName)) {
77 | return lifecycleMap.get(lcName);
78 | }
79 | throw new LifecycleException("Lifecycle configuration does not exist with name " + lcName);
80 | }
81 |
82 | /**
83 | * Initiates the static lifecycle map during startup.
84 | */
85 | //TODO : move to seperate class. not util
86 | public static void initiateLCMap() {
87 | lifecycleMap = new ConcurrentHashMap<>();
88 | String defaultLifecycleConfigLocation = getDefaltLifecycleConfigLocation();
89 | File defaultLifecycleConfigDirectory = new File(defaultLifecycleConfigLocation);
90 | if (!defaultLifecycleConfigDirectory.exists()) {
91 | return;
92 | }
93 |
94 | final FilenameFilter filenameFilter = (dir, name) -> name.endsWith(".xml");
95 |
96 | File[] lifecycleConfigFiles = defaultLifecycleConfigDirectory.listFiles(filenameFilter);
97 | if (lifecycleConfigFiles == null || lifecycleConfigFiles.length == 0) {
98 | return;
99 | }
100 |
101 | for (File lifecycleConfigFile : lifecycleConfigFiles) {
102 | String fileName = FilenameUtils.removeExtension(lifecycleConfigFile.getName());
103 | //here configuration file name should be same as aspect name
104 | String fileContent = null;
105 |
106 | try {
107 | fileContent = FileUtils.readFileToString(lifecycleConfigFile);
108 | } catch (IOException e) {
109 | String msg = String.format("Error while reading lifecycle config file %s ", fileName);
110 | log.error(msg, e);
111 | /* The exception is not thrown, because if we throw the error, the for loop will be broken and
112 | other files won't be read */
113 | }
114 | if ((fileContent != null) && !fileContent.isEmpty()) {
115 | try {
116 | Document lcConfig = getLifecycleElement(fileContent);
117 | Element element = (Element) lcConfig
118 | .getElementsByTagName(LifecycleConstants.ASPECT).item(0);
119 | String lcName = element.getAttribute("name");
120 | if (fileName.equalsIgnoreCase(lcName)) {
121 | validateLifecycleContent(fileContent);
122 | validateSCXMLDataModel(lcConfig);
123 | getLifecycleMapInstance().put(lcName, lcConfig);
124 | } else {
125 | String msg = String
126 | .format("Configuration file name %s not matched with lifecycle name %s ", fileName,
127 | lcName);
128 | log.error(msg);
129 | /* The error is not thrown, because if we throw the error, the for loop will be broken and
130 | other files won't be read */
131 | }
132 | } catch (LifecycleException e) {
133 | String msg = String.format("Error while adding lifecycle %s ", fileName);
134 | log.error(msg, e);
135 |
136 | }
137 | }
138 | }
139 |
140 | }
141 |
142 | /**
143 | * This method is used to get the initial state defined in the lifecycle
144 | *
145 | * @param lcName : lifecycle name
146 | * @return : initial state
147 | * @throws LifecycleException If failed to get initial state.
148 | */
149 | public static String getInitialState(String lcName) throws LifecycleException {
150 | return LifecycleOperationUtil.getInitialState(getLifecycleConfiguration(lcName), lcName);
151 | }
152 |
153 | /**
154 | * This method is used to read lifecycle config and provide permission details associated with each state change.
155 | *
156 | * @param lcConfig Lifecycle configuration element.
157 | * @return Document element for the lifecycle confi
158 | * @throws LifecycleException If failed to get lifecycle element.
159 | */
160 | public static Document getLifecycleElement(String lcConfig) throws LifecycleException {
161 |
162 | try {
163 | InputStream inputStream = new ByteArrayInputStream(lcConfig.getBytes(StandardCharsets.UTF_8));
164 | DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
165 | documentBuilderFactory.setNamespaceAware(false);
166 | Document document = documentBuilderFactory.newDocumentBuilder().parse(inputStream);
167 | return document;
168 | } catch (SAXException | IOException | ParserConfigurationException e) {
169 | throw new LifecycleException("Error while building lifecycle config document element", e);
170 | }
171 | }
172 |
173 | /**
174 | * Method used to validate lifecycle config adheres to the schema.
175 | * @param lcConfig Lifecycle configuration element.
176 | * @throws LifecycleException If validation fails.
177 | */
178 | public static void validateLifecycleContent(String lcConfig) throws LifecycleException {
179 | if (!validateLifecycleContent(lcConfig, getLifecycleSchemaValidator(getLifecycleSchemaLocation()))) {
180 | String message = "Unable to validate the lifecycle configuration";
181 | log.error(message);
182 | throw new LifecycleException(message);
183 | }
184 | }
185 |
186 | private static boolean validateLifecycleContent(String lcConfig, Validator validator) {
187 | try {
188 | InputStream is = new ByteArrayInputStream(lcConfig.getBytes("utf-8"));
189 | Source xmlFile = new StreamSource(is);
190 | if (validator != null) {
191 | validator.validate(xmlFile);
192 | } else {
193 | log.error(
194 | "Lifecycle schema validator not found. Check the existence of resources/lifecycle-config.xsd");
195 | }
196 | } catch (SAXException e) {
197 | log.error("Unable to parse the XML configuration. Please validate the XML configuration", e);
198 | return false;
199 | } catch (UnsupportedEncodingException e) {
200 | log.error("Unsupported content", e);
201 | return false;
202 | } catch (IOException e) {
203 | log.error("Unable to parse the XML configuration. Please validate the XML configuration", e);
204 | return false;
205 | }
206 | return true;
207 | }
208 |
209 | private static void validateSCXMLDataModel(Document lcConfig) throws LifecycleException {
210 | NodeList stateList = lcConfig.getElementsByTagName(LifecycleConstants.STATE_TAG);
211 |
212 | for (int i = 0; i < stateList.getLength(); i++) {
213 | List targetValues = new ArrayList<>();
214 | if (stateList.item(i).getNodeType() == Node.ELEMENT_NODE) {
215 | Element state = (Element) stateList.item(i);
216 | String stateName = state.getAttribute("id");
217 | NodeList targetList = state.getElementsByTagName(LifecycleConstants.TRANSITION_ATTRIBUTE);
218 | for (int targetCount = 0; targetCount < targetList.getLength(); targetCount++) {
219 | if (targetList.item(targetCount).getNodeType() == Node.ELEMENT_NODE) {
220 | Element target = (Element) targetList.item(targetCount);
221 | targetValues.add(target.getAttribute(LifecycleConstants.TARGET_ATTRIBUTE));
222 | }
223 | }
224 | XPath xPathInstance = XPathFactory.newInstance().newXPath();
225 | String xpathQuery = "//state[@id='" + stateName + "']//@forTarget";
226 | try {
227 | XPathExpression exp = xPathInstance.compile(xpathQuery);
228 | NodeList forTargetNodeList = (NodeList) exp.evaluate(state, XPathConstants.NODESET);
229 | for (int forTargetCount = 0; forTargetCount < forTargetNodeList.getLength(); forTargetCount++) {
230 | if (forTargetNodeList.item(forTargetCount).getNodeType() == Node.ATTRIBUTE_NODE) {
231 | Attr attr = (Attr) forTargetNodeList.item(forTargetCount);
232 | if (!"".equals(attr.getValue()) && !targetValues.contains(attr.getValue())) {
233 | throw new LifecycleException("forTarget attribute value " + attr.getValue()
234 | + " does not included as target state in the state object " + stateName);
235 | }
236 | }
237 | }
238 | } catch (XPathExpressionException e) {
239 | throw new LifecycleException("Error while reading for target attributes ", e);
240 | }
241 |
242 | }
243 | }
244 |
245 | }
246 |
247 | /**
248 | * Method used to get schema validator object for lifecycle configurations.
249 | * @param schemaPath Schema path in the server extracted directory.
250 | * @return schema validator object
251 | */
252 | public static synchronized Validator getLifecycleSchemaValidator(String schemaPath) {
253 | if (lifecycleSchemaValidator != null) {
254 | return lifecycleSchemaValidator;
255 | }
256 | try {
257 | SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
258 | Schema schema = schemaFactory.newSchema(new File(schemaPath));
259 | lifecycleSchemaValidator = schema.newValidator();
260 | } catch (SAXException e) {
261 | log.error("Unable to get a schema validator from the given file path : " + schemaPath);
262 | }
263 | return lifecycleSchemaValidator;
264 | }
265 |
266 | private static synchronized Map getLifecycleMapInstance() {
267 | if (lifecycleMap == null) {
268 | lifecycleMap = new ConcurrentHashMap<>();
269 | }
270 |
271 | return lifecycleMap;
272 | }
273 |
274 | /**
275 | * This method will return the lifecycle schema location in the server directory.
276 | * @return schema location.
277 | */
278 | private static String getLifecycleSchemaLocation() {
279 | return Utils.getRuntimePath() + File.separator + "resources" + File.separator + "lifecycle-config.xsd";
280 | }
281 |
282 | private static String getDefaltLifecycleConfigLocation() {
283 | return Utils.getRuntimePath() + File.separator + "resources" + File.separator + "lifecycles";
284 | }
285 | }
286 |
--------------------------------------------------------------------------------
/components/org.wso2.carbon.lcm.core/src/main/java/org/wso2/carbon/lcm/core/LifecycleOperationManager.java:
--------------------------------------------------------------------------------
1 | package org.wso2.carbon.lcm.core;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.w3c.dom.Document;
6 | import org.wso2.carbon.lcm.core.beans.CustomCodeBean;
7 | import org.wso2.carbon.lcm.core.exception.LifecycleException;
8 | import org.wso2.carbon.lcm.core.impl.LifecycleState;
9 | import org.wso2.carbon.lcm.core.util.LifecycleOperationUtil;
10 | import org.wso2.carbon.lcm.core.util.LifecycleUtils;
11 | import org.wso2.carbon.lcm.sql.beans.LifecycleStateBean;
12 |
13 | import java.util.List;
14 |
15 | import static org.wso2.carbon.lcm.core.util.LifecycleOperationUtil.changeCheckListItem;
16 | import static org.wso2.carbon.lcm.core.util.LifecycleOperationUtil.getInitialState;
17 | import static org.wso2.carbon.lcm.core.util.LifecycleOperationUtil.populateItems;
18 | import static org.wso2.carbon.lcm.core.util.LifecycleOperationUtil.removeLifecycleStateData;
19 |
20 | /**
21 | * This is the class provides all the logic related to lifecycle operations. (Associate, Dissociate, State change
22 | * event and Check list item event)
23 | */
24 | public class LifecycleOperationManager {
25 |
26 | private static Logger log = LoggerFactory.getLogger(LifecycleOperationManager.class);
27 |
28 | /**
29 | * This method need to call for each and event life cycle state changes.
30 | *
31 | * @param targetState {@code String} Required target state.
32 | * @param uuid {@code String} Lifecycle id that maps with the asset.
33 | * @param resource {@code Object} The current object to which lifecycle is attached to.
34 | * @param user The user who invoked the action. This will be used for auditing
35 | * purposes.
36 | * @return {@code LifecycleState} object of updated life cycle state.
37 | * @throws LifecycleException If exception occurred while execute life cycle state change.
38 | */
39 | public static LifecycleState executeLifecycleEvent(String targetState, String uuid, String user, Object resource)
40 | throws LifecycleException {
41 | LifecycleState nextState = new LifecycleState();
42 | LifecycleState currentState = LifecycleOperationUtil.getCurrentLifecycleState(uuid);
43 | if (!validateTargetState(currentState, targetState)) {
44 | throw new LifecycleException("The specified target state " + targetState + " is not a valid target state. "
45 | + "Can't transit from " + currentState + "to" + targetState);
46 | }
47 | if (!validateCheckListItemSelected(currentState, targetState)) {
48 | throw new LifecycleException(
49 | "Required checklist items are not selected to perform the state transition operation from "
50 | + currentState.getState() + " to " + targetState);
51 | }
52 | String lcName = currentState.getLcName();
53 | Document lcContent = LifecycleUtils.getLifecycleConfiguration(lcName);
54 | runCustomExecutorsCode(resource, currentState.getCustomCodeBeanList(), currentState.getState(), targetState);
55 | populateItems(nextState, lcContent);
56 | nextState.setState(targetState);
57 | nextState.setLcName(currentState.getLcName());
58 | nextState.setLifecycleId(currentState.getLifecycleId());
59 | LifecycleOperationUtil.changeLifecycleState(currentState.getState(), targetState, uuid, user);
60 |
61 | if (log.isDebugEnabled()) {
62 | log.debug("Lifecycle state was changed from " + currentState.getState() + " to " + targetState
63 | + " for lifecycle id " + uuid);
64 | }
65 | return nextState;
66 | }
67 |
68 | /**
69 | * This method need to call for each and event life cycle state changes.
70 | *
71 | * @param currentState {@code String} Current state
72 | * @param targetState {@code String} Required target state.
73 | * @param uuid {@code String} Lifecycle id that maps with the asset.
74 | * @param resource {@code Object} The current object to which lifecycle is attached to.
75 | * @param user The user who invoked the action. This will be used for auditing
76 | * purposes.
77 | * @return {@code LifecycleState} object of updated life cycle state.
78 | * @throws LifecycleException If exception occurred while execute life cycle state change.
79 | */
80 | public static LifecycleState executeLifecycleEvent(String currentState, String targetState, String uuid, String
81 | user, Object resource)
82 | throws LifecycleException {
83 | LifecycleState nextState = new LifecycleState();
84 | LifecycleState currentLifecycleState = getLifecycleDataForState(uuid, currentState);
85 | if (!validateTargetState(currentLifecycleState, targetState)) {
86 | throw new LifecycleException("The specified target state " + targetState + " is not a valid target state. "
87 | + "Can't transit from " + currentState + " to " + targetState);
88 | }
89 | if (!validateCheckListItemSelected(currentLifecycleState, targetState)) {
90 | throw new LifecycleException(
91 | "Required checklist items are not selected to perform the state transition operation from "
92 | + currentLifecycleState.getState() + " to " + targetState);
93 | }
94 | String lcName = currentLifecycleState.getLcName();
95 | Document lcContent = LifecycleUtils.getLifecycleConfiguration(lcName);
96 | runCustomExecutorsCode(resource, currentLifecycleState.getCustomCodeBeanList(), currentLifecycleState
97 | .getState(), targetState);
98 | populateItems(nextState, lcContent);
99 | nextState.setState(targetState);
100 | nextState.setLcName(currentLifecycleState.getLcName());
101 | nextState.setLifecycleId(currentLifecycleState.getLifecycleId());
102 | LifecycleOperationUtil.changeLifecycleState(currentLifecycleState.getState(), targetState, uuid, user);
103 |
104 | if (log.isDebugEnabled()) {
105 | log.debug("Lifecycle state was changed from " + currentLifecycleState.getState() + " to " + targetState
106 | + " for lifecycle id " + uuid);
107 | }
108 | return nextState;
109 | }
110 |
111 | /**
112 | * This method need to call for each check list item operation.
113 | *
114 | * @param uuid Object that can use to uniquely identify resource.
115 | * @param currentState The state which the checklist item is associated with.
116 | * @param checkListItemName Name of the check list item as specified in the lc config.
117 | * @param value Value of the check list item. Either selected or not.
118 | * @return updated LifecycleState
119 | * @throws LifecycleException If exception occurred while execute life cycle update.
120 | */
121 | public static LifecycleState checkListItemEvent(String uuid, String currentState, String checkListItemName,
122 | boolean value) throws LifecycleException {
123 | changeCheckListItem(uuid, currentState, checkListItemName, value);
124 | LifecycleState currentStateObject = LifecycleOperationUtil.getCurrentLifecycleState(uuid);
125 |
126 | if (log.isDebugEnabled()) {
127 | log.debug("Check list item " + checkListItemName + " is set to " + value);
128 | }
129 | return currentStateObject;
130 | }
131 |
132 |
133 | /**
134 | * This method is used to associate a lifecycle with an asset.
135 | *
136 | * @param lcName LC name which associates with the resource.
137 | * @param user The user who invoked the action. This will be used for auditing purposes.
138 | * @return Object of added life cycle state.
139 | * @throws LifecycleException If failed to associate life cycle with asset.
140 | */
141 | public static LifecycleState addLifecycle(String lcName, String user) throws LifecycleException {
142 | LifecycleState lifecycleState;
143 | Document lcContent = LifecycleUtils.getLifecycleConfiguration(lcName);
144 | lifecycleState = new LifecycleState();
145 |
146 | String initialState = getInitialState(lcContent, lcName);
147 | lifecycleState.setLcName(lcName);
148 | lifecycleState.setState(initialState);
149 | populateItems(lifecycleState, lcContent);
150 | String lifecycleId = LifecycleOperationUtil.associateLifecycle(lcName, initialState, user);
151 |
152 | lifecycleState.setLifecycleId(lifecycleId);
153 | if (log.isDebugEnabled()) {
154 | log.debug("Id : " + lifecycleId + " associated with lifecycle " + lcName + " and initial state set to "
155 | + initialState);
156 | }
157 | return lifecycleState;
158 | }
159 |
160 | /**
161 | * This method is used to associate a lifecycle with an asset. Lifecycle Id can be specified in the request
162 | * @param lcName LC name which associates with the resource.
163 | * @param lifecycleId Unique lifecycle ID
164 | * @param user The user who invoked the action. This will be used for auditing purposes.
165 | * @return Object of added life cycle state.
166 | * @throws LifecycleException If failed to associate life cycle with asset.
167 | */
168 | public static LifecycleState addLifecycle(String lcName, String lifecycleId, String user) throws
169 | LifecycleException {
170 | LifecycleState lifecycleState;
171 | Document lcContent = LifecycleUtils.getLifecycleConfiguration(lcName);
172 | lifecycleState = new LifecycleState();
173 |
174 | String initialState = getInitialState(lcContent, lcName);
175 | lifecycleState.setLcName(lcName);
176 | lifecycleState.setState(initialState);
177 | populateItems(lifecycleState, lcContent);
178 | LifecycleOperationUtil.associateLifecycle(lcName, lifecycleId, initialState, user);
179 |
180 | lifecycleState.setLifecycleId(lifecycleId);
181 | if (log.isDebugEnabled()) {
182 | log.debug("Id : " + lifecycleId + " associated with lifecycle " + lcName + " and initial state set to "
183 | + initialState);
184 | }
185 | return lifecycleState;
186 | }
187 |
188 | /**
189 | * This method is used to detach a lifecycle from an asset.
190 | *
191 | * @param uuid Lifecycle id that maps with the asset.
192 | * @throws LifecycleException If failed to associate life cycle with asset.
193 | */
194 | public static void removeLifecycle(String uuid) throws LifecycleException {
195 | removeLifecycleStateData(uuid);
196 | }
197 |
198 | /**
199 | * Get current life cycle state object.
200 | * @param uuid uuid of the LifecycleState
201 | * @return {@code LifecycleState} object represent current life cycle.
202 | * @throws LifecycleException
203 | */
204 | public static LifecycleState getCurrentLifecycleState(String uuid) throws LifecycleException {
205 | LifecycleState currentLifecycleState = new LifecycleState();
206 | LifecycleStateBean lifecycleStateBean = LifecycleOperationUtil.getLCStateDataFromID(uuid);
207 | String lcName = lifecycleStateBean.getLcName();
208 | Document lcContent = LifecycleUtils.getLifecycleConfiguration(lcName);
209 | currentLifecycleState.setLcName(lcName);
210 | currentLifecycleState.setLifecycleId(uuid);
211 | currentLifecycleState.setState(lifecycleStateBean.getPostStatus());
212 | populateItems(currentLifecycleState, lcContent);
213 | LifecycleOperationUtil.setCheckListItemData(currentLifecycleState, lifecycleStateBean.getCheckListData());
214 | return currentLifecycleState;
215 | }
216 |
217 | public static LifecycleState getLifecycleDataForState (String uuid, String lcState) throws LifecycleException {
218 | LifecycleState currentLifecycleState = new LifecycleState();
219 | LifecycleStateBean lifecycleStateBean = LifecycleOperationUtil.getLCDataFromState(uuid, lcState);
220 | String lcName = lifecycleStateBean.getLcName();
221 | Document lcContent = LifecycleUtils.getLifecycleConfiguration(lcName);
222 | currentLifecycleState.setLcName(lcName);
223 | currentLifecycleState.setLifecycleId(uuid);
224 | currentLifecycleState.setState(lcState);
225 | populateItems(currentLifecycleState, lcContent);
226 | LifecycleOperationUtil.setCheckListItemData(currentLifecycleState, lifecycleStateBean.getCheckListData());
227 | return currentLifecycleState;
228 | }
229 |
230 |
231 | /**
232 | * This method is used to run custom executor codes.
233 | *
234 | * @param resource The asset to which the lc is attached
235 | * @return success of execution class.
236 | * @throws LifecycleException if failed to run custom executors.
237 | */
238 | private static boolean runCustomExecutorsCode(Object resource, List customCodeBeans,
239 | String currentState, String nextState) throws LifecycleException {
240 | if (customCodeBeans != null) {
241 | for (CustomCodeBean customCodeBean : customCodeBeans) {
242 | if (customCodeBean.getTargetName().equals(nextState)) {
243 | Executor customExecutor = (Executor) customCodeBean.getClassObject();
244 | customExecutor.execute(resource, currentState, nextState);
245 | }
246 | }
247 | }
248 | return true;
249 | }
250 |
251 | private static boolean validateCheckListItemSelected(LifecycleState lifecycleState, String nextState) {
252 | return !lifecycleState.getCheckItemBeanList().stream()
253 | .anyMatch(checkItemBean -> checkItemBean.getTargets().contains(nextState) && !checkItemBean.isValue());
254 | }
255 |
256 | private static boolean validateTargetState (LifecycleState lifecycleState, String nextState) {
257 | return lifecycleState.getAvailableTransitionBeanList().stream().anyMatch(availableTransitionBean ->
258 | availableTransitionBean.getTargetState().equals(nextState));
259 | }
260 | }
261 |
262 |
--------------------------------------------------------------------------------