fix: 支持新版的ITSM资源的CRUD操作,包括deployment, process-definition, process-instance, task, historic-process-instance, historic-task-instance

This commit is contained in:
ningyu
2019-04-26 14:49:51 +08:00
parent 78d9972d20
commit b43f0626d0
12 changed files with 698 additions and 0 deletions
+92
View File
@@ -0,0 +1,92 @@
// Copyright 2019 Yunion
//
// 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 shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
/**
* 使用文件创建部署
*/
type DeploymentCreateOptions struct {
FILE string `help:"The local bpmn filename to Upload"`
}
R(&DeploymentCreateOptions{}, "process-deployment-create", "Create deployment by upload BPMN file", func(s *mcclient.ClientSession, args *DeploymentCreateOptions) error {
// TODO
return nil
})
/**
* 删除指定ID的部署
*/
type DeploymentDeleteOptions struct {
ID string `help:"ID of process deployment"`
Cascade bool `help:"Whether to cascade delete process instance, history process instance and jobs" required:"true" choices:"true|false"`
}
R(&DeploymentDeleteOptions{}, "process-deployment-delete", "Delete process deployment by ID", func(s *mcclient.ClientSession, args *DeploymentDeleteOptions) error {
params := jsonutils.NewDict()
if args.Cascade {
params.Add(jsonutils.JSONTrue, "cascade")
} else {
params.Add(jsonutils.JSONFalse, "cascade")
}
result, e := modules.ProcessDeployments.Delete(s, args.ID, nil)
if e != nil {
return e
}
printObject(result)
return nil
})
/**
* 列出部署
*/
type DeploymentListOptions struct {
options.BaseListOptions
}
R(&DeploymentListOptions{}, "process-deployment-list", "List process deployment", func(s *mcclient.ClientSession, args *DeploymentListOptions) error {
params, err := options.ListStructToParams(args)
if err != nil {
return err
}
result, err := modules.ProcessDeployments.List(s, params)
if err != nil {
return err
}
printList(result, modules.ProcessDeployments.GetColumns(s))
return nil
})
/**
* 查看指定ID的部署
*/
type DeploymentShowOptions struct {
ID string `help:"ID of the process deployment"`
}
R(&DeploymentShowOptions{}, "process-deployment-show", "Show deployment", func(s *mcclient.ClientSession, args *DeploymentShowOptions) error {
result, err := modules.ProcessDeployments.Get(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
}
@@ -0,0 +1,67 @@
// Copyright 2019 Yunion
//
// 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 shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
/**
* 列出历史流程实例
*/
type HistoricProcessInstanceListOptions struct {
ProcessDefinitionKey string `help:"Process definition key"`
UserId string `help:"ID of user"`
options.BaseListOptions
}
R(&HistoricProcessInstanceListOptions{}, "historic-process-instance-list", "List historic process definition", func(s *mcclient.ClientSession, args *HistoricProcessInstanceListOptions) error {
params, err := options.StructToParams(args)
if err != nil {
return err
}
if len(args.ProcessDefinitionKey) > 0 {
params.Add(jsonutils.NewString(args.ProcessDefinitionKey), "process_definition_key")
}
if len(args.UserId) > 0 {
params.Add(jsonutils.NewString(args.UserId), "user_id")
}
result, err := modules.HistoricProcessInstance.List(s, params)
if err != nil {
return err
}
printList(result, modules.HistoricProcessInstance.GetColumns(s))
return nil
})
/**
* 查看指定ID的历史流程实例
*/
type HistoricProcessInstanceShowOptions struct {
ID string `help:"ID of the historic process instance"`
}
R(&HistoricProcessInstanceShowOptions{}, "historic-process-instance-show", "Show historic process definition", func(s *mcclient.ClientSession, args *HistoricProcessInstanceShowOptions) error {
result, err := modules.HistoricProcessInstance.Get(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
}
@@ -0,0 +1,67 @@
// Copyright 2019 Yunion
//
// 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 shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
/**
* 列出历史任务实例
*/
type HistoricProcessInstanceListOptions struct {
ProcessInstanceId string `help:"ID of process instance"`
UserId string `help:"ID of user"`
options.BaseListOptions
}
R(&HistoricProcessInstanceListOptions{}, "historic-task-instance-list", "List historic process instance", func(s *mcclient.ClientSession, args *HistoricProcessInstanceListOptions) error {
params, err := options.StructToParams(args)
if err != nil {
return err
}
if len(args.ProcessInstanceId) > 0 {
params.Add(jsonutils.NewString(args.ProcessInstanceId), "process_instance_id")
}
if len(args.UserId) > 0 {
params.Add(jsonutils.NewString(args.UserId), "user_id")
}
result, err := modules.HistoricTaskInstances.List(s, params)
if err != nil {
return err
}
printList(result, modules.HistoricTaskInstances.GetColumns(s))
return nil
})
/**
* 查看指定ID的历史任务实例
*/
type HistoricProcessInstanceShowOptions struct {
ID string `help:"ID of the historic task instance"`
}
R(&HistoricProcessInstanceShowOptions{}, "historic-task-instance-show", "Show historic task instance", func(s *mcclient.ClientSession, args *HistoricProcessInstanceShowOptions) error {
result, err := modules.HistoricTaskInstances.Get(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
}
+107
View File
@@ -0,0 +1,107 @@
// Copyright 2019 Yunion
//
// 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 shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
/**
* 删除指定ID的流程定义
*/
type ProcessDefinitionDeleteOptions struct {
ID string `help:"ID of process definition, deletes the process definition which belongs to the given process definition id"`
Cascade bool `help:"Whether to cascade delete process instance, if set to true, all process instances (including) history are deleted" required:"true" choices:"true|false"`
}
R(&ProcessDefinitionDeleteOptions{}, "process-definition-delete", "Delete process definition by ID", func(s *mcclient.ClientSession, args *ProcessDefinitionDeleteOptions) error {
params := jsonutils.NewDict()
if args.Cascade {
params.Add(jsonutils.JSONTrue, "cascade")
} else {
params.Add(jsonutils.JSONFalse, "cascade")
}
result, e := modules.ProcessDefinitions.Delete(s, args.ID, nil)
if e != nil {
return e
}
printObject(result)
return nil
})
/**
* 修改指定的流程定义的激活/挂起状态
*/
type NodealertUpdateOptions struct {
ID string `help:"ID of process definition"`
state string `help:"State of the process definition" choices:"activate|suspend"`
}
R(&NodealertUpdateOptions{}, "process-definition-change-state", "Update the state of the process definition", func(s *mcclient.ClientSession, args *NodealertUpdateOptions) error {
params := jsonutils.NewDict()
params.Add(jsonutils.NewString(args.state), "state")
result, err := modules.ProcessDefinitions.Put(s, args.ID, params)
if err != nil {
return err
}
printObject(result)
return nil
})
/**
* 列出流程定义
*/
type ProcessDefinitionListOptions struct {
ProcessDefinitionKey string `help:"Key of process definition"`
UserId string `help:"ID of user who start the process definition"`
options.BaseListOptions
}
R(&ProcessDefinitionListOptions{}, "process-definition-list", "List process definition", func(s *mcclient.ClientSession, args *ProcessDefinitionListOptions) error {
params, err := options.ListStructToParams(args)
if err != nil {
return err
}
if len(args.ProcessDefinitionKey) > 0 {
params.Add(jsonutils.NewString(args.ProcessDefinitionKey), "process_definition_key")
}
if len(args.UserId) > 0 {
params.Add(jsonutils.NewString(args.UserId), "user_id")
}
result, err := modules.ProcessDefinitions.List(s, params)
if err != nil {
return err
}
printList(result, modules.ProcessDefinitions.GetColumns(s))
return nil
})
/**
* 查看指定ID的流程定义
*/
type ProcessDefinitionShowOptions struct {
ID string `help:"ID of the process definition"`
}
R(&ProcessDefinitionShowOptions{}, "process-definition-show", "Show process definition", func(s *mcclient.ClientSession, args *ProcessDefinitionShowOptions) error {
result, err := modules.ProcessDefinitions.Get(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
}
+108
View File
@@ -0,0 +1,108 @@
// Copyright 2019 Yunion
//
// 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 shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
/**
* 创建流程实例(发起流程)
*/
type ProcessInstanceCreateOptions struct {
PROCESS_DEFINITION_KEY string `help:"Key of the process definition"`
INITIATOR string `help:"ID of user who launch the process instance"`
ASSIGNEE string `help:"ID of assignee"`
SERVER_CREATE_PARAMTER string `help:"Onecloud server create spec json string"`
}
R(&ProcessInstanceCreateOptions{}, "process-instance-create", "Create process instance", func(s *mcclient.ClientSession, args *ProcessInstanceCreateOptions) error {
variables_params := jsonutils.NewDict()
variables_params.Add(jsonutils.NewString(args.PROCESS_DEFINITION_KEY), "process_definition_key")
variables_params.Add(jsonutils.NewString(args.INITIATOR), "initiator")
variables_params.Add(jsonutils.NewString(args.ASSIGNEE), "assignee")
variables_params.Add(jsonutils.NewString(args.SERVER_CREATE_PARAMTER), "server-create-paramter")
params := jsonutils.NewDict()
params.Add(variables_params, "variables")
result, err := modules.ProcessInstance.Create(s, params)
if err != nil {
return err
}
printObject(result)
return nil
})
/**
* 删除指定ID的流程实例
*/
type ProcessInstanceDeleteOptions struct {
ID string `help:"ID of process process"`
DeleteReason string `help:"Reason why delete the process instance" required:"true" choices:"true|false"`
}
R(&ProcessInstanceDeleteOptions{}, "process-instance-delete", "Delete process instance by ID", func(s *mcclient.ClientSession, args *ProcessInstanceDeleteOptions) error {
params := jsonutils.NewDict()
if len(args.DeleteReason) > 0 {
params.Add(jsonutils.NewString(args.DeleteReason), "delete_reason")
}
result, e := modules.ProcessInstance.Delete(s, args.ID, nil)
if e != nil {
return e
}
printObject(result)
return nil
})
/**
* 列出流程实例
*/
type ProcessInstanceListOptions struct {
ProcessDefinitionId string `help:"ID of process definition"`
options.BaseListOptions
}
R(&ProcessInstanceListOptions{}, "process-instance-list", "List process instance", func(s *mcclient.ClientSession, args *ProcessInstanceListOptions) error {
params, err := options.ListStructToParams(args)
if err != nil {
return err
}
if len(args.ProcessDefinitionId) > 0 {
params.Add(jsonutils.NewString(args.ProcessDefinitionId), "process_definition_id")
}
result, err := modules.ProcessInstance.List(s, params)
if err != nil {
return err
}
printList(result, modules.ProcessInstance.GetColumns(s))
return nil
})
/**
* 查看指定ID的流程实例
*/
type ProcessInstanceShowOptions struct {
ID string `help:"ID of the process instance"`
}
R(&ProcessInstanceShowOptions{}, "process-instance-show", "Show process instance", func(s *mcclient.ClientSession, args *ProcessInstanceShowOptions) error {
result, err := modules.ProcessInstance.Get(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
}
+95
View File
@@ -0,0 +1,95 @@
// Copyright 2019 Yunion
//
// 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 shell
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
func init() {
/**
* 处理任务
*/
type TaskOperOperateOptions struct {
ID string `help:"ID of task"`
APPROVAL_DECISION bool `help:"Approval decision" choices:"true|false"`
ApprovalProposal string `help:"Approval proposal"`
}
R(&TaskOperOperateOptions{}, "process-task-operate", "Operate task", func(s *mcclient.ClientSession, args *TaskOperOperateOptions) error {
variables_params := jsonutils.NewDict()
if args.APPROVAL_DECISION {
variables_params.Add(jsonutils.JSONTrue, "approved")
} else {
variables_params.Add(jsonutils.JSONFalse, "approved")
}
if len(args.ApprovalProposal) > 0 {
variables_params.Add(jsonutils.NewString(args.ApprovalProposal), "comment")
}
params := jsonutils.NewDict()
params.Add(variables_params, "variables")
result, err := modules.ProcessTasks.Put(s, args.ID, params)
if err != nil {
return err
}
printObject(result)
return nil
})
/**
* 列出任务
*/
type TaskListOptions struct {
UserId string `help:"Id of user"`
GroupId string `help:"ID of group"`
options.BaseListOptions
}
R(&TaskListOptions{}, "process-task-list", "List task", func(s *mcclient.ClientSession, args *TaskListOptions) error {
params, err := options.ListStructToParams(args)
if err != nil {
return err
}
if len(args.UserId) > 0 {
params.Add(jsonutils.NewString(args.UserId), "user_id")
}
if len(args.GroupId) > 0 {
params.Add(jsonutils.NewString(args.GroupId), "group_id")
}
result, err := modules.ProcessTasks.List(s, params)
if err != nil {
return err
}
printList(result, modules.ProcessTasks.GetColumns(s))
return nil
})
/**
* 查看指定ID的任务
*/
type TaskShowOptions struct {
ID string `help:"ID of the task"`
}
R(&TaskShowOptions{}, "process-task-show", "Show task details", func(s *mcclient.ClientSession, args *TaskShowOptions) error {
result, err := modules.ProcessTasks.Get(s, args.ID, nil)
if err != nil {
return err
}
printObject(result)
return nil
})
}
@@ -0,0 +1,27 @@
// Copyright 2019 Yunion
//
// 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 modules
var (
ProcessDeployments ResourceManager
)
func init() {
ProcessDeployments = NewITSMManager("process-deployment", "process-deployments",
[]string{"id", "name", "source", "deployment_time", "tenant_id"},
[]string{},
)
register(&ProcessDeployments)
}
@@ -0,0 +1,27 @@
// Copyright 2019 Yunion
//
// 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 modules
var (
HistoricProcessInstance ResourceManager
)
func init() {
HistoricProcessInstance = NewITSMManager("historic-process-instance", "historic-process-instances",
[]string{"id", "process_definition_key", "start_activity_id", "end_time", "duration_in_millis", "removal_time", "business_key", "end_activity_id", "process_definition_version", "delete_reason", "process_definition_id", "start_time", "start_user_id", "case_instance_id", "root_process_instance_id", "super_case_instance_id", "state", "process_definition_name", "super_process_instance_id", "tenant_id"},
[]string{},
)
register(&HistoricProcessInstance)
}
@@ -0,0 +1,27 @@
// Copyright 2019 Yunion
//
// 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 modules
var (
HistoricTaskInstances ResourceManager
)
func init() {
HistoricTaskInstances = NewITSMManager("historic-task-instance", "historic-task-instances",
[]string{"id", "name", "parent_task_id", "duration_in_millis", "description", "case_execution_id", "removal_time", "delete_reason", "follow_up_date", "execution_id", "activity_instance_id", "root_process_instance_id", "owner", "process_definition_key", "end_time", "due_date", "super_case_instance_id", "priority", "process_definition_id", "start_time", "case_definition_key", "case_instance_id", "process_instance_id", "case_definition_id", "assignee", "task_definition_key"},
[]string{},
)
register(&HistoricTaskInstances)
}
@@ -0,0 +1,27 @@
// Copyright 2019 Yunion
//
// 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 modules
var (
ProcessDefinitions ResourceManager
)
func init() {
ProcessDefinitions = NewITSMManager("process-definition", "process-definitions",
[]string{"id", "name", "key", "description", "resource_name", "diagram_resource_name", "deployment_id", "startable_in_tasklist", "category", "suspended", "start_form_key", "history_time_to_live", "version", "version_tag", "tenant_id"},
[]string{},
)
register(&ProcessDefinitions)
}
@@ -0,0 +1,27 @@
// Copyright 2019 Yunion
//
// 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 modules
var (
ProcessInstance ResourceManager
)
func init() {
ProcessInstance = NewITSMManager("process-instance", "process-instances",
[]string{"id", "process_instance_id", "root_process_instance_id", "case_instance_id", "business_key", "ended", "suspended", "tenant_id"},
[]string{},
)
register(&ProcessInstance)
}
+27
View File
@@ -0,0 +1,27 @@
// Copyright 2019 Yunion
//
// 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 modules
var (
ProcessTasks ResourceManager
)
func init() {
ProcessTasks = NewITSMManager("process-task", "process-tasks",
[]string{"id", "name", "description", "owner", "priority", "tenant_id"},
[]string{},
)
register(&ProcessTasks)
}