-/*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.onap.ccsdk.apps.blueprintsprocessor.core.api.data\r
-\r
-import com.fasterxml.jackson.annotation.JsonFormat\r
-import com.fasterxml.jackson.databind.node.ObjectNode\r
-import io.swagger.annotations.ApiModelProperty\r
-import java.util.*\r
-\r
-/**\r
- * BlueprintProcessorData\r
- * @author Brinda Santh\r
- * DATE : 8/15/2018\r
- */\r
-\r
-open class ExecutionServiceInput {\r
- @get:ApiModelProperty(required = true)\r
- lateinit var commonHeader: CommonHeader\r
- @get:ApiModelProperty(required = true)\r
- lateinit var actionIdentifiers: ActionIdentifiers\r
- @get:ApiModelProperty(required = true)\r
- lateinit var payload: ObjectNode\r
-}\r
-\r
-open class ExecutionServiceOutput {\r
- @get:ApiModelProperty(required = true)\r
- lateinit var commonHeader: CommonHeader\r
- @get:ApiModelProperty(required = true)\r
- lateinit var actionIdentifiers: ActionIdentifiers\r
- @get:ApiModelProperty(required = true)\r
- var status: Status = Status()\r
- @get:ApiModelProperty(required = true)\r
- lateinit var payload: ObjectNode\r
-}\r
-\r
-open class ActionIdentifiers {\r
- @get:ApiModelProperty(required = false)\r
- lateinit var blueprintName: String\r
- @get:ApiModelProperty(required = false)\r
- lateinit var blueprintVersion: String\r
- @get:ApiModelProperty(required = true)\r
- lateinit var actionName: String\r
- @get:ApiModelProperty(required = true, allowableValues = "sync, async")\r
- lateinit var mode: String\r
-}\r
-\r
-open class CommonHeader {\r
- @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z")\r
- @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")\r
- var timestamp: Date = Date()\r
- @get:ApiModelProperty(required = true)\r
- lateinit var originatorId: String\r
- @get:ApiModelProperty(required = true)\r
- lateinit var requestId: String\r
- @get:ApiModelProperty(required = true)\r
- lateinit var subRequestId: String\r
- @get:ApiModelProperty(required = false)\r
- var flags: Flags? = null\r
-}\r
-\r
-open class Flags {\r
- var isForce: Boolean = false\r
- @get:ApiModelProperty(value = "3600")\r
- var ttl: Int = 3600\r
-}\r
-\r
-open class Status {\r
- @get:ApiModelProperty(required = true)\r
- var code: Int = 200\r
- @get:ApiModelProperty(required = true)\r
- var eventType: String = "EVENT-ACTION-RESPONSE"\r
- @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z")\r
- @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")\r
- var timestamp: Date = Date()\r
- @get:ApiModelProperty(required = false)\r
- var errorMessage: String? = null\r
- @get:ApiModelProperty(required = true)\r
- var message: String = "success"\r
-}\r
-\r
-\r
-\r
-\r
-\r
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.blueprintsprocessor.core.api.data
+
+import com.fasterxml.jackson.annotation.JsonFormat
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.swagger.annotations.ApiModelProperty
+import java.util.*
+
+/**
+ * BlueprintProcessorData
+ * @author Brinda Santh
+ * DATE : 8/15/2018
+ */
+
+open class ExecutionServiceInput {
+ @get:ApiModelProperty(required = true)
+ lateinit var commonHeader: CommonHeader
+ @get:ApiModelProperty(required = true)
+ lateinit var actionIdentifiers: ActionIdentifiers
+ @get:ApiModelProperty(required = true)
+ lateinit var payload: ObjectNode
+}
+
+open class ExecutionServiceOutput {
+ @get:ApiModelProperty(required = true)
+ lateinit var commonHeader: CommonHeader
+ @get:ApiModelProperty(required = true)
+ lateinit var actionIdentifiers: ActionIdentifiers
+ @get:ApiModelProperty(required = true)
+ var status: Status = Status()
+ @get:ApiModelProperty(required = true)
+ lateinit var payload: ObjectNode
+}
+
+const val ACTION_MODE_ASYNC = "async"
+const val ACTION_MODE_SYNC = "sync"
+
+open class ActionIdentifiers {
+ @get:ApiModelProperty(required = false)
+ lateinit var blueprintName: String
+ @get:ApiModelProperty(required = false)
+ lateinit var blueprintVersion: String
+ @get:ApiModelProperty(required = true)
+ lateinit var actionName: String
+ @get:ApiModelProperty(required = true, allowableValues = "sync, async")
+ lateinit var mode: String
+}
+
+open class CommonHeader {
+ @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z")
+ @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+ var timestamp: Date = Date()
+ @get:ApiModelProperty(required = true)
+ lateinit var originatorId: String
+ @get:ApiModelProperty(required = true)
+ lateinit var requestId: String
+ @get:ApiModelProperty(required = true)
+ lateinit var subRequestId: String
+ @get:ApiModelProperty(required = false)
+ var flags: Flags? = null
+}
+
+open class Flags {
+ var isForce: Boolean = false
+ @get:ApiModelProperty(value = "3600")
+ var ttl: Int = 3600
+}
+
+open class Status {
+ @get:ApiModelProperty(required = true)
+ var code: Int = 200
+ @get:ApiModelProperty(required = true)
+ var eventType: String = "EVENT-ACTION-RESPONSE"
+ @get:ApiModelProperty(required = true, example = "2012-04-23T18:25:43.511Z")
+ @get:JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+ var timestamp: Date = Date()
+ @get:ApiModelProperty(required = false)
+ var errorMessage: String? = null
+ @get:ApiModelProperty(required = true)
+ var message: String = "success"
+}
package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.launch
import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_ASYNC
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ACTION_MODE_SYNC
import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status
import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils.saveCBAFile
import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.BlueprintDGExecutionService
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils
}
fun process(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
+ return when {
+ executionServiceInput.actionIdentifiers.mode == ACTION_MODE_ASYNC -> {
+ GlobalScope.launch(Dispatchers.Default) {
+ // TODO post result in DMaaP
+ val executionServiceOutput = doProcess(executionServiceInput)
+ }
+ response(executionServiceInput)
+ }
+ executionServiceInput.actionIdentifiers.mode == ACTION_MODE_SYNC -> doProcess(executionServiceInput)
+ else -> response(executionServiceInput, true)
+ }
+ }
+ fun doProcess(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
val requestId = executionServiceInput.commonHeader.requestId
log.info("processing request id $requestId")
return blueprintDGExecutionService.executeDirectedGraph(blueprintRuntimeService, executionServiceInput)
}
+
+ fun response(executionServiceInput: ExecutionServiceInput, failure: Boolean = false): ExecutionServiceOutput {
+ val executionServiceOutput = ExecutionServiceOutput()
+ executionServiceOutput.commonHeader = executionServiceInput.commonHeader
+ executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers
+ executionServiceOutput.payload = executionServiceInput.payload
+
+ val status = Status()
+ if (failure) {
+ status.eventType = "EVENT-COMPONENT-FAILURE"
+ status.code = 500
+ status.message = BluePrintConstants.STATUS_FAILURE
+ } else {
+ status.eventType = "EVENT-COMPONENT-PROCESSING"
+ status.code = 200
+ status.message = BluePrintConstants.STATUS_PROCESSING
+ }
+
+ executionServiceOutput.status = status
+
+ return executionServiceOutput
+ }
}
\ No newline at end of file