-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvision_wsclient.module
202 lines (172 loc) · 5.94 KB
/
envision_wsclient.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
/**
* @file
* Web service client examples module.
*/
/**
* Implements hook_commerce_checkout_page_info().
*/
function envision_wsclient_commerce_checkout_page_info() {
$checkout_pages = array();
$checkout_pages['checkout_to_webservice'] = array(
'name' => t('checkout to webservice'),
'title' => t('Connect to remote server'),
'weight' => 4,
'buttons' => TRUE,
);
$checkout_pages['input_vapp_name'] = array(
'name' => t('virtual Application Name'),
'title' => t('Virtual Application Name'),
'weight' => 3,
'buttons' => TRUE,
);
return $checkout_pages;
}
/**
* Implements hook_commerce_checkout_pane_info().
*/
function envision_wsclient_commerce_checkout_pane_info() {
$checkout_panes = array();
$checkout_panes['envision_wsclient'] = array(
'title' => t('Envision WSClient'),
'base' => 'envision_wsclient_pane',
'file' => 'includes/envision_wsclient.checkout_pane.inc',
'page' => 'checkout_to_webservice',
'weight' => 3,
'review' => FALSE,
);
$checkout_panes['input_vapp_name_pane'] = array(
'title' => t('Virtual application items are ready to create.'),
'base' => 'envision_wsclient_input_vapp_pane',
'file' => 'includes/envision_wsclient.input_vapp_name.inc',
'page' => 'input_vapp_name',
'weight' => 2,
'review' => FALSE,
);
return $checkout_panes;
}
/**
* Implements hook_menu().
* for testing
*/
function envision_wsclient_menu() {
$items['test/restful'] = array(
'page callback' => 'exec_wsclient',
'file' => 'envision_wsclient.test.inc',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_default_wsclient_service().
*/
function envision_wsclient_default_wsclient_service() {
$service = new WSClientServiceDescription();
$service->name = 'envision_webservice';
$service->label = 'Envision Webservice';
$service->url = 'http://218.4.19.204:8081/envision/restful/';
$service->type = 'rest';
// Add info about the REST service, which the user has to provide via the UI.
$service->datatypes = array(
'return_result' => array(
'label' => 'Return Result',
'property info' => array(
'responseData' => array(
'type' => 'text',
'label' => 'Return Result'
),
),
),
);
//create operation
$operation['label'] = 'Create';
$operation['url'] = 'createvApp';
$operation['parameter']['serviceName'] = array('type' => 'text', 'label' => 'ServiceName');
$operation['parameter']['hireDays'] = array('type' => 'text', 'label' => 'hireDays');
$operation['parameter']['templateName'] = array('type' => 'text', 'label' => 'templateName');
$operation['type']='POST';
$service->operations['create'] = $operation;
//delete by name operation
$operation = array();
$operation['label'] = 'DeleteByName';
$operation['url'] = 'deletevAppByName';
$operation['parameter']['serviceName'] = array('type' => 'text', 'label' => 'ServiceName');
$operation['type']='POST';
$service->operations['delete_by_name'] = $operation;
//delete by id operation
$operation = array();
$operation['label'] = 'DeleteById';
$operation['url'] = 'deletevAppById';
$operation['parameter']['vappId'] = array('type' => 'text', 'label' => 'vappId');
$operation['type']='POST';
$service->operations['delete_by_id'] = $operation;
//deploy by id operation
$operation = array();
$operation['label'] = 'DeployById';
$operation['url'] = 'deployvAppById';
$operation['parameter']['vappId'] = array('type' => 'text', 'label' => 'vappId');
$operation['parameter']['action'] = array('type' => 'text', 'label' => 'Action');
$operation['type']='POST';
$service->operations['deploy_by_id'] = $operation;
//power by id operation
$operation = array();
$operation['label'] = 'PowerById';
$operation['url'] = 'powervAppById';
$operation['parameter']['vappId'] = array('type' => 'text', 'label' => 'vappId');
$operation['parameter']['action'] = array('type' => 'text', 'label' => 'Action');
$operation['type']='POST';
$service->operations['power_by_id'] = $operation;
//find by id operation
$operation = array();
$operation['label'] = 'FindById';
$operation['url'] = 'findvAppById';
$operation['parameter']['vappId'] = array('type' => 'text', 'label' => 'vappId');
$operation['type']='POST';
$service->operations['find_by_id'] = $operation;
//Asynchronous Create vApp
$operation = array();
$operation['label'] = 'AsyncCreatevApp';
$operation['url'] = 'asyncCreatevApp';
$operation['parameter']['serviceName'] = array('type' => 'text', 'label' => 'ServiceName');
$operation['parameter']['hireDays'] = array('type' => 'text', 'label' => 'hireDays');
$operation['parameter']['templateName'] = array('type' => 'text', 'label' => 'templateName');
$operation['type']='POST';
$service->operations['async_create'] = $operation;
//Asynchronous Track task by task ID
$operation = array();
$operation['label'] = 'TrackTaskById';
$operation['url'] = 'trackTaskById';
$operation['parameter']['taskId'] = array('type' => 'text', 'label' => 'Task ID');
$operation['type']='POST';
$service->operations['track_by_id'] = $operation;
$services[$service->name] = $service;
return $services;
}
/**
* Implements hook_node_delete().
*/
function envision_wsclient_node_delete($node) {
if($node->type=='running_service'){
$service = wsclient_service_load('envision_webservice');
try {
$result = $service->delete_by_name($node->title);
}catch (WSClientException $e) {
drupal_set_message($e->__toString(),'error');
$result = $e->__toString();
}
//dpm($result);
}
}
/**
* Implements hook_cron().
*/
function envision_wsclient_cron() {
drupal_set_message('Hello:'.time());
$result = db_query("SELECT nid FROM {node} WHERE type = :type AND field_progress <> :progress",
array(
':type' => 'running_service', ':progress' => 100,
));
dpm($result);
}