diff --git a/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/Actions.kt b/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/Actions.kt index dba27362..a27926b3 100644 --- a/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/Actions.kt +++ b/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/Actions.kt @@ -40,6 +40,7 @@ val ipamHasAllocationMode = "ipamHasAllocationMode" val ipamHasNotAllocationMode = "ipamHasNotAllocationMode" val networkHasNotAllcationMode = "networkHasNotAllocationMode" val propertyOfObjectRule = "propertyOfObjectRule" +val listTagTypes = "listTagTypes" val portOfVCVirtualMachine = "portOfVCVirtualMachine" val networkOfVCPortGroup = "networkOfVCPortGroup" \ No newline at end of file diff --git a/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/Config.kt b/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/Config.kt index 4b780c34..a0798a03 100644 --- a/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/Config.kt +++ b/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/Config.kt @@ -74,7 +74,8 @@ val customCreateWorkflows = setOf( the(), the(), the(), - the() + the(), + the() ) val customEditWorkflows = setOf( @@ -88,7 +89,8 @@ val customEditWorkflows = setOf( val customDeleteWorkflows = setOf( the(), - the() + the(), + the() ) val directChildren = setOf( diff --git a/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/constants/Constants.kt b/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/constants/Constants.kt index 23dfc35d..ab257a4b 100644 --- a/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/constants/Constants.kt +++ b/o11nplugin-contrail-config/src/main/kotlin/net/juniper/contrail/vro/config/constants/Constants.kt @@ -19,6 +19,7 @@ val Connection = "Connection" val parent = "parent" val child = "child" val item = "item" +val name = "name" val id = "id" val ingress = "ingress" val egress = "egress" diff --git a/o11nplugin-contrail-core/src/main/kotlin/net/juniper/contrail/vro/model/Executor.kt b/o11nplugin-contrail-core/src/main/kotlin/net/juniper/contrail/vro/model/Executor.kt index 9fa6328f..7182ba85 100644 --- a/o11nplugin-contrail-core/src/main/kotlin/net/juniper/contrail/vro/model/Executor.kt +++ b/o11nplugin-contrail-core/src/main/kotlin/net/juniper/contrail/vro/model/Executor.kt @@ -10,6 +10,7 @@ import net.juniper.contrail.api.types.InstanceIp import net.juniper.contrail.api.types.VirtualMachineInterface import net.juniper.contrail.api.types.ServiceTemplate import net.juniper.contrail.api.types.ServiceInstance +import net.juniper.contrail.api.types.TagType // To reduce complexity of one class, the functionality has been split between multiple simpler classes. // They are combined using inheritance so that their functions become Executor's methods. @@ -44,4 +45,7 @@ NetworkPolicyRuleProperties by NetworkPolicyRulePropertyExecutor(connection) { if (properties.interfaceList.size <= index || index < 0) return null return connection.findByFQN(properties.interfaceList[index].virtualNetwork) } + + fun Connection.listTagTypes(): List = + list()?.asSequence()?.map { it.name }?.sorted()?.toList() ?: emptyList() } \ No newline at end of file diff --git a/o11nplugin-contrail-custom/src/main/kotlin/net/juniper/contrail/vro/CustomManagedType.kt b/o11nplugin-contrail-custom/src/main/kotlin/net/juniper/contrail/vro/CustomManagedType.kt index da04ba0a..d10480a4 100644 --- a/o11nplugin-contrail-custom/src/main/kotlin/net/juniper/contrail/vro/CustomManagedType.kt +++ b/o11nplugin-contrail-custom/src/main/kotlin/net/juniper/contrail/vro/CustomManagedType.kt @@ -39,7 +39,6 @@ private val executorTypes = Executor::class.java.declaredMethods.asSequence() .groupBy { it.parameterTypes[0] } private fun ManagedType.createExecutorMethods(): List { - if (!modelClass.isApiObjectClass) return emptyList() val methods = executorTypes[modelClass] ?: emptyList() return methods.map { it.toExecutorMethod() } } diff --git a/o11nplugin-contrail-custom/src/main/resources/net/juniper/contrail/vro/data.ftl b/o11nplugin-contrail-custom/src/main/resources/net/juniper/contrail/vro/data.ftl index 79d55588..a3689ed8 100644 --- a/o11nplugin-contrail-custom/src/main/resources/net/juniper/contrail/vro/data.ftl +++ b/o11nplugin-contrail-custom/src/main/resources/net/juniper/contrail/vro/data.ftl @@ -157,6 +157,42 @@ public class ${className} <@singletonMethod /> + <#if objectClass || connectionClass> + public Connection_Wrapper getConnection() { + <#if connectionClass> + <#-- This special case is here to provide consistent API for all findable objects. --> + return this; + <#else> + return (Connection_Wrapper) util.findConnectionWrapper(getInternalId()); + + } + + + <#list executorMethods as m> + <@compress single_line=true>public ${m.returns.typeName} ${m.name}(<@params m />)<@thrown m /> { + <@locals m /> + + ${m.returns.fullClassName} _res$ = util.executor(getInternalId()).${m.name}(__getTarget()<#if m.params?has_content>,<@localNames m />); + + <#if m.returns.fullClassName != 'boolean'> + if(_res$ == null) return null; + + + ${m.returns.typeName} _res$pl = _ctx.createPluginObject(_res$, ${m.returns.convertFriendlyClassName}); + <#if m.returns.componentTypeName??> + <#if m.returns.componentClassName??> + for(int i = 0; i < _res$.size(); i++) { + _res$pl.get(i).setInternalId(getInternalId().with("${m.returns.componentTypeName}",_res$.get(i).getUuid())); + } + <#else> + _res$pl.setInternalId(getInternalId().with("${m.returns.componentTypeName}",_res$.getUuid())); + + + return _res$pl; + } + + + <#if objectClass > <#list parents as parent> public void setParent${parent.simpleName}(${packageName}.${parent.simpleName}_Wrapper _parent) { @@ -192,35 +228,6 @@ public class ${className} util.delete(getInternalId(), __getTarget()); } - public Connection_Wrapper getConnection() { - return (Connection_Wrapper) util.findConnectionWrapper(getInternalId()); - } - - <#list executorMethods as m> - <@compress single_line=true>public ${m.returns.typeName} ${m.name}(<@params m />)<@thrown m /> { - <@locals m /> - - ${m.returns.fullClassName} _res$ = util.executor(getInternalId()).${m.name}(__getTarget()<#if m.params?has_content>,<@localNames m />); - - <#if m.returns.fullClassName != 'boolean'> - if(_res$ == null) return null; - - - ${m.returns.typeName} _res$pl = _ctx.createPluginObject(_res$, ${m.returns.convertFriendlyClassName}); - <#if m.returns.componentTypeName??> - <#if m.returns.componentClassName??> - for(int i = 0; i < _res$.size(); i++) { - _res$pl.get(i).setInternalId(getInternalId().with("${m.returns.componentTypeName}",_res$.get(i).getUuid())); - } - <#else> - _res$pl.setInternalId(getInternalId().with("${m.returns.componentTypeName}",_res$.getUuid())); - - - return _res$pl; - } - - - <#list references as ref> //List returned by this method is read-only. Changes to the list will not be reflected in the state of the object. public java.util.List<${ref.className}_Wrapper> ${ref.pluginMethodName}() { diff --git a/o11nplugin-contrail-workflows/src/main/js/actions/listTagTypes.js b/o11nplugin-contrail-workflows/src/main/js/actions/listTagTypes.js new file mode 100644 index 00000000..1001b5b8 --- /dev/null +++ b/o11nplugin-contrail-workflows/src/main/js/actions/listTagTypes.js @@ -0,0 +1,3 @@ +if (!item) return ["application", "deployment", "label", "site", "tier"]; +var connection = item.getConnection(); +return connection.listTagTypes(); \ No newline at end of file diff --git a/o11nplugin-contrail-workflows/src/main/js/workflows/createGlobalTag.js b/o11nplugin-contrail-workflows/src/main/js/workflows/createGlobalTag.js index 3484c488..ea431b07 100644 --- a/o11nplugin-contrail-workflows/src/main/js/workflows/createGlobalTag.js +++ b/o11nplugin-contrail-workflows/src/main/js/workflows/createGlobalTag.js @@ -1,8 +1,7 @@ -var type = typeName.toLowerCase(); item = new ContrailTag(); -item.setName(type+"="+value); +item.setName(typeName+"="+value); item.setParentConfigRoot(new ContrailConfigRoot()); item.setParentConnection(parent); item.setValue(value); -item.setTypeName(type); +item.setTypeName(typeName); item.create(); \ No newline at end of file diff --git a/o11nplugin-contrail-workflows/src/main/js/workflows/createTagInProject.js b/o11nplugin-contrail-workflows/src/main/js/workflows/createTagInProject.js index b507acd5..5090c347 100644 --- a/o11nplugin-contrail-workflows/src/main/js/workflows/createTagInProject.js +++ b/o11nplugin-contrail-workflows/src/main/js/workflows/createTagInProject.js @@ -1,7 +1,6 @@ -var type = typeName.toLowerCase(); item = new ContrailTag(); -item.setName(type+"="+value); +item.setName(typeName+"="+value); item.setParentProject(parent); item.setValue(value); -item.setTypeName(type); +item.setTypeName(typeName); item.create(); \ No newline at end of file diff --git a/o11nplugin-contrail-workflows/src/main/js/workflows/createTagType.js b/o11nplugin-contrail-workflows/src/main/js/workflows/createTagType.js new file mode 100644 index 00000000..99fe3450 --- /dev/null +++ b/o11nplugin-contrail-workflows/src/main/js/workflows/createTagType.js @@ -0,0 +1,4 @@ +item = new ContrailTagType(); +item.setName(name); +item.setParentConnection(parent); +item.create(); \ No newline at end of file diff --git a/o11nplugin-contrail-workflows/src/main/js/workflows/deleteTagType.js b/o11nplugin-contrail-workflows/src/main/js/workflows/deleteTagType.js new file mode 100644 index 00000000..f485a8f2 --- /dev/null +++ b/o11nplugin-contrail-workflows/src/main/js/workflows/deleteTagType.js @@ -0,0 +1 @@ +item.delete(); \ No newline at end of file diff --git a/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/GeneralActions.kt b/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/GeneralActions.kt index 2ac4b8bb..028b571b 100644 --- a/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/GeneralActions.kt +++ b/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/GeneralActions.kt @@ -5,12 +5,14 @@ package net.juniper.contrail.vro.workflows.custom import net.juniper.contrail.vro.config.constants.item +import net.juniper.contrail.vro.config.listTagTypes import net.juniper.contrail.vro.config.propertyNotNull import net.juniper.contrail.vro.config.propertyOfObjectRule import net.juniper.contrail.vro.config.propertyValue import net.juniper.contrail.vro.config.readSubnet import net.juniper.contrail.vro.workflows.dsl.ofType import net.juniper.contrail.vro.workflows.model.any +import net.juniper.contrail.vro.workflows.model.array import net.juniper.contrail.vro.workflows.model.boolean import net.juniper.contrail.vro.workflows.model.string @@ -51,4 +53,12 @@ val propertyOfObjectRule = ActionDefinition( "rule" ofType string, "propertyName" ofType string ) +) + +val listTagTypesAction = ActionDefinition ( + name = listTagTypes, + resultType = string.array, + parameters = listOf( + item ofType any + ) ) \ No newline at end of file diff --git a/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/Tag.kt b/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/Tag.kt index a84d415c..ddb9142e 100644 --- a/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/Tag.kt +++ b/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/Tag.kt @@ -10,21 +10,15 @@ import net.juniper.contrail.api.types.Tag import net.juniper.contrail.vro.config.allCapitalized import net.juniper.contrail.vro.config.constants.Connection import net.juniper.contrail.vro.config.constants.parent +import net.juniper.contrail.vro.config.listTagTypes import net.juniper.contrail.vro.schema.Schema import net.juniper.contrail.vro.workflows.dsl.WorkflowDefinition +import net.juniper.contrail.vro.workflows.dsl.actionCallTo import net.juniper.contrail.vro.workflows.model.reference import net.juniper.contrail.vro.workflows.model.string import net.juniper.contrail.vro.workflows.util.propertyDescription import net.juniper.contrail.vro.workflows.util.relationDescription -private val tagTypes = listOf( - "Application", - "Tier", - "Deployment", - "Site", - "Label" -) - internal fun createGlobalTag(schema: Schema) = createTag(schema, global = true) @@ -39,18 +33,18 @@ private fun createTag(schema: Schema, global: Boolean): WorkflowDefinition { return customWorkflow(workflowName).withScriptFile(scriptName) { description = relationDescription(schema) + parameter(parent, parentName.reference) { + description = "Parent ${parentName.allCapitalized}" + mandatory = true + } parameter("typeName", string) { description = propertyDescription(schema) - predefinedAnswers = tagTypes + predefinedAnswersFrom = actionCallTo(listTagTypes).parameter(parent) mandatory = true } parameter("value", string) { description = propertyDescription(schema) mandatory = true } - parameter(parent, parentName.reference) { - description = "Parent ${parentName.allCapitalized}" - mandatory = true - } } } \ No newline at end of file diff --git a/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/TagType.kt b/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/TagType.kt new file mode 100644 index 00000000..d0a02b33 --- /dev/null +++ b/o11nplugin-contrail-workflows/src/main/kotlin/net/juniper/contrail/vro/workflows/custom/TagType.kt @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Juniper Networks, Inc. All rights reserved. + */ + +package net.juniper.contrail.vro.workflows.custom + +import net.juniper.contrail.api.types.TagType +import net.juniper.contrail.vro.config.constants.Connection +import net.juniper.contrail.vro.config.constants.name +import net.juniper.contrail.vro.config.constants.item +import net.juniper.contrail.vro.config.constants.parent +import net.juniper.contrail.vro.workflows.dsl.WorkflowDefinition +import net.juniper.contrail.vro.workflows.model.reference +import net.juniper.contrail.vro.workflows.model.string + +internal fun createTagType(): WorkflowDefinition { + + val workflowName = "Create tag type" + + return customWorkflow(workflowName).withScriptFile("createTagType") { + parameter(name, string) { + description = "Name of the tag type" + mandatory = true + } + parameter(parent, Connection.reference) { + description = "Parent connection" + mandatory = true + } + output(item, reference()) { + description = "Tag Type created in this workflow" + } + } +} + +internal fun deleteTagType(): WorkflowDefinition { + + val workflowName = "Delete tag type" + + return customWorkflow(workflowName).withScriptFile("deleteTagType") { + parameter(item, reference()) { + description = "Tag Type to delete" + mandatory = true + } + } +} \ No newline at end of file