VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/CloudClientImpl.cpp@ 73535

Last change on this file since 73535 was 73535, checked in by vboxsync, 6 years ago

bugref:9152. New classes CloudAPI, OCIIAM, OCIObjectStorage, OCICompute, CloudCommandCl, DataModel, DataParser and their descendants.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.2 KB
Line 
1/* $Id: CloudClientImpl.cpp 73535 2018-08-06 22:10:52Z vboxsync $*/
2/** @file
3 * ICloudClient COM class implementations.
4 */
5
6/*
7 * Copyright (C) 2008-2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include <iostream>
19#include <algorithm>
20#include <map>
21
22#include <iprt/path.h>
23#include <iprt/cpp/utils.h>
24#include <VBox/com/array.h>
25
26#include "CloudClientImpl.h"
27#include "CloudUserProfileManagerImpl.h"
28#include "CloudUserProfilesImpl.h"
29#include "CloudAPI.h"
30#include "VirtualBoxImpl.h"
31#include "Global.h"
32#include "MachineImpl.h"
33#include "AutoCaller.h"
34#include "Logging.h"
35
36using namespace std;
37
38
39////////////////////////////////////////////////////////////////////////////////
40//
41// CloudClient implementation
42//
43////////////////////////////////////////////////////////////////////////////////
44CloudClient::CloudClient()
45 : mParent(NULL)
46{
47 LogRel(("CloudClient::CloudClient()\n"));
48}
49
50CloudClient::~CloudClient()
51{
52 LogRel(("CloudClient::~CloudClient()\n"));
53}
54
55HRESULT CloudClient::FinalConstruct()
56{
57 return BaseFinalConstruct();
58}
59
60void CloudClient::FinalRelease()
61{
62 uninit();
63
64 BaseFinalRelease();
65}
66
67void CloudClient::uninit()
68{
69 LogRel(("CloudClient::uninit()\n"));
70 /* Enclose the state transition Ready->InUninit->NotReady */
71 AutoUninitSpan autoUninitSpan(this);
72 if (autoUninitSpan.uninitDone())
73 return;
74
75 unconst(mParent) = NULL;
76
77 {
78 std::map <com::Guid, CloudCommandCl*>::iterator it = mCloudCommandMap.begin();
79 while (it != mCloudCommandMap.end())
80 {
81 delete it->second;
82 ++it;
83 }
84 }
85
86 {
87 std::map <Utf8Str, CloudAPI*>::iterator it = mCloudAPIInstanceMap.begin();
88 while (it != mCloudAPIInstanceMap.end())
89 {
90 delete it->second;
91 ++it;
92 }
93 }
94}
95
96HRESULT CloudClient::init(VirtualBox *aParent)
97{
98 LogRel(("aParent=%p\n", aParent));
99 ComAssertRet(aParent, E_INVALIDARG);
100
101 /* Enclose the state transition NotReady->InInit->Ready */
102 AutoInitSpan autoInitSpan(this);
103 AssertReturn(autoInitSpan.isOk(), E_FAIL);
104
105 unconst(mParent) = aParent;
106
107 mCloudProvider = CloudProviderId_OCI;
108
109 LogRel(("aParent=%p\n", aParent));
110
111 /*
112 * Confirm a successful initialization
113 */
114 autoInitSpan.setSucceeded();
115
116 return S_OK;
117}
118
119HRESULT CloudClient::initCloudClient(CloudUserProfiles *aProfiles,
120 VirtualBox *aParent,
121 CloudProviderId_T aCloudProvider,
122 const com::Utf8Str &aProfileName)
123{
124 LogRel(("aParent=%p\n", aParent));
125 ComAssertRet(aParent, E_INVALIDARG);
126
127 /* Enclose the state transition NotReady->InInit->Ready */
128 AutoInitSpan autoInitSpan(this);
129 AssertReturn(autoInitSpan.isOk(), E_FAIL);
130
131 unconst(mParent) = aParent;
132
133 HRESULT hrc = S_OK;
134
135 try
136 {
137 mCloudProvider = aCloudProvider;
138 LogRel(("CloudProvider = %d\n", mCloudProvider));
139 CloudUserProfiles *lProfiles = aProfiles;
140 std::vector<com::Utf8Str> lNames;
141 std::vector<com::Utf8Str> lValues;
142 hrc = lProfiles->getProfileProperties(aProfileName, lNames, lValues);
143 if (FAILED(hrc))
144 {
145 return hrc;
146 }
147
148 for (size_t i=0;i<lNames.size();++i)
149 {
150 com::Utf8Str value = (i<lValues.size()) ? lValues.at(i) : "";
151 mCloudProfile[lNames.at(i)] = value;
152 }
153
154 CloudProviderId_T aProvider;
155 hrc = lProfiles->getProvider(&aProvider);
156
157 switch(aProvider)
158 {
159 case CloudProviderId_OCI:
160 default:
161 LogRel(("Reading profile %s has been done\n", aProfileName.c_str()));
162 break;
163 }
164 }
165 catch (HRESULT arc)
166 {
167 hrc = arc;
168 LogRel(("Get cought an exception %d\n", hrc));
169 }
170 catch (std::bad_alloc &)
171 {
172 return E_OUTOFMEMORY;
173 }
174
175 /*
176 * Confirm a successful initialization
177 */
178 autoInitSpan.setSucceeded();
179
180 return hrc;
181}
182
183HRESULT CloudClient::createCommand(CloudCommand_T aCloudCommand, com::Guid &aId)
184{
185 HRESULT hrc = S_OK;
186 LogRel(("CloudClient::createCommand: %s \n", aCloudCommand));
187 int vrc = i_createCommand(aCloudCommand, aId);
188 if (RT_FAILURE(vrc))
189 hrc = setErrorBoth(E_FAIL, vrc, tr("Couldn't create command %d"), aCloudCommand);
190
191 return hrc;
192}
193
194int CloudClient::i_createCommand(CloudCommand_T aCloudCommand, com::Guid &aId)
195{
196 LogRel(("Enter CloudClient::i_createCommand()\n"));
197 int vrc = VINF_SUCCESS;
198
199 try
200 {
201 CloudAPI* actualAPI = NULL;
202 Utf8Str apiName;
203 vrc = i_queryAPINameForCommand(aCloudCommand, apiName);
204 if (RT_SUCCESS(vrc) && mCloudAPIInstanceMap[apiName] == NULL)
205 {
206 vrc = i_queryAPIForCommand(aCloudCommand, &actualAPI);
207 if (RT_SUCCESS(vrc) && actualAPI != NULL)
208 mCloudAPIInstanceMap[apiName] = actualAPI;
209 }
210 else
211 actualAPI = mCloudAPIInstanceMap[apiName];
212
213 if (RT_SUCCESS(vrc))
214 {
215 com::Guid lId;
216 lId.create();
217 CloudCommandCl *newCloudCommand = NULL;
218
219 actualAPI->createCloudCommand(aCloudCommand, mCloudProfile, lId, &newCloudCommand);
220 newCloudCommand->mAPIBaseURI = actualAPI->getBaseAPIUrl(actualAPI->getDefaultVersion(), mCloudProfile);
221 if (!newCloudCommand->mAPIBaseURI.isEmpty())
222 {
223 LogRel(("Base API \"%s\" URI is %s \n", apiName.c_str(), newCloudCommand->mAPIBaseURI.c_str()));
224 newCloudCommand->mUsedAPI = actualAPI;
225 mCloudCommandMap.insert(make_pair(newCloudCommand->mId, newCloudCommand));
226 aId = newCloudCommand->mId;
227 }
228 else
229 vrc = VERR_NOT_FOUND;
230 }
231
232 }
233 catch (int arc)
234 {
235 vrc = arc;
236 LogRel(("Get cought an exception %d\n", vrc));
237 }
238
239 return vrc;
240}
241
242HRESULT CloudClient::runCommand(const com::Guid &aId, LONG64 aTimeout, CloudCommandResult_T *aResult)
243{
244 LogRel(("CloudClient::runCommand: %s, %d\n", aId.toString().c_str(), aTimeout));
245 HRESULT hrc = S_OK;
246 std::map <com::Guid, CloudCommandCl*>::iterator it = mCloudCommandMap.find(aId);
247 if (it !=mCloudCommandMap.end() && it->second->mfValid == true)
248 {
249 CloudCommandCl* cc = it->second;
250 cc->mTimeout = aTimeout;
251 int vrc = i_runCommand(*cc);
252 if (RT_FAILURE(vrc))
253 {
254 hrc = setErrorBoth(E_FAIL, vrc, tr("Execution of the command with UUID \"%s\" was failed"),
255 aId.toString().c_str());
256 *aResult = CloudCommandResult_success;
257 }
258 else
259 *aResult = CloudCommandResult_failed;
260 }
261 else
262 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Command with UUID \"%s\" wasn't found or hasn't been validated yet"),
263 aId.toString().c_str());
264
265 return hrc;
266}
267
268//int CloudClient::i_runCommand(CloudCommandCl &aCC, ComObjPtr<Progress> *aProgress)
269//{
270// LogRel(("Enter CloudClient::i_runCommand()\n"));
271// int vrc = aCC.mUsedAPI->callAPICommand(aCC, aProgress);
272// return vrc;
273//}
274
275int CloudClient::i_runCommand(CloudCommandCl &aCC)
276{
277 LogRel(("Enter CloudClient::i_runCommand()\n"));
278 int vrc = aCC.mUsedAPI->callAPICommand(aCC);
279 return vrc;
280}
281
282HRESULT CloudClient::validateCommand(const com::Guid &aId, BOOL *aValid)
283{
284 HRESULT hrc = S_OK;
285 //check all data in the operation and set the flag
286 //this step allows easy to control which operation may be launch
287 std::map <com::Guid, CloudCommandCl*>::const_iterator cit = mCloudCommandMap.find(aId);
288 if (cit != mCloudCommandMap.end())
289 {
290 std::map<Utf8Str, Utf8Str> paramNameValueMap;
291 int vrc = i_validateCommand(*(cit->second), paramNameValueMap, false);
292 if (RT_SUCCESS(vrc))
293 *aValid = true;
294 else
295 {
296 *aValid = false;
297 hrc = setErrorBoth(E_FAIL, vrc, tr("The command %d not validated"), cit->second->mCommand);
298 }
299 }
300 else
301 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Command with UUID \"%s\" wasn't found"),
302 aId.toString().c_str());
303 return hrc;
304}
305
306int CloudClient::i_validateCommand(CloudCommandCl &aCC,
307 const std::map<Utf8Str, Utf8Str> &aParamNameValueMap,
308 bool fWeak)
309{
310 LogRel(("Enter CloudClient::i_validateCommand()\n"));
311 int vrc = VINF_SUCCESS;
312// bool isSimple = false;
313// vrc = i_isSimpleCommand(aCC, isSimple);
314// if (!isSimple)//parameters are needed for the command
315 {
316 std::vector<com::Utf8Str> paramNames;
317 paramNames.reserve(15);
318 std::map<Utf8Str, Utf8Str> freshParamNameValueMap;
319
320 vrc = i_getCommandParameterNames(aCC, paramNames);
321 if (RT_SUCCESS(vrc))
322 {
323 for (size_t i=0;i<paramNames.size();++i)
324 {
325 std::map <Utf8Str, Utf8Str>::const_iterator cit = aParamNameValueMap.find(paramNames.at(i));
326 if (cit != aParamNameValueMap.end())
327 freshParamNameValueMap.insert(make_pair(cit->first,cit->second));
328 else
329 {
330 if (fWeak)
331 vrc = VINF_TRY_AGAIN;
332 else
333 vrc = VERR_NOT_FOUND;
334
335 break;
336 }
337 }
338
339 if (RT_SUCCESS(vrc) && vrc != VINF_TRY_AGAIN)
340 {
341 std::map <Utf8Str, Utf8Str>::const_iterator cit = freshParamNameValueMap.begin();
342 while (cit != freshParamNameValueMap.end())
343 {
344 //insert new parameter/value or update old one
345 aCC.mParameters[cit->first] = cit->second;
346 ++cit;
347 }
348
349 aCC.mfValid = true;
350 }
351 else
352 aCC.mfValid = false;
353 }
354 }
355
356 return vrc;
357}
358
359HRESULT CloudClient::checkCommandResult(const com::Guid &aId,
360 LONG64 *aStartTime,
361 LONG64 *aLastTime,
362 CloudCommandResult_T *aResult)
363{
364 HRESULT hrc = S_OK;
365 int vrc = VINF_SUCCESS;
366 LogRel(("CloudClient::checkCommandResult: %s, %d, %d, %d\n",
367 aId.toString().c_str(),
368 *aStartTime,
369 *aLastTime,
370 aResult));
371 std::map <com::Guid, CloudCommandCl*>::const_iterator cit = mCloudCommandMap.find(aId);
372 if (cit != mCloudCommandMap.end())
373 {
374 CloudCommandResult_T res;
375 CloudCommandCl *cc = cit->second;
376 vrc = i_checkCommandResult(*cc, res);
377 if (RT_FAILURE(vrc))
378 hrc = setErrorBoth(E_FAIL, vrc, tr("Coudn't get the result for command with UUID \"%s\" "),
379 aId.toString().c_str());
380 else
381 *aResult = res;
382 }
383 else
384 {
385 vrc = VERR_NOT_FOUND;
386 if (RT_FAILURE(vrc))
387 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Command with UUID \"%s\" wasn't found"),
388 aId.toString().c_str());
389 }
390
391 return hrc;
392}
393
394int CloudClient::i_checkCommandResult(CloudCommandCl &aCC,
395 CloudCommandResult_T &aResult)
396{
397 LogRel(("Enter CloudClient::i_checkCommandResult()\n"));
398 RT_NOREF(aCC, aResult);
399 int vrc = VINF_SUCCESS;//aCC.parseResult(aResult);
400 return vrc;
401}
402
403int CloudClient::i_parseResponse(CloudCommandCl &aCC)
404{
405 LogRel(("Enter CloudClient::i_parseResponse()\n"));
406 int vrc = VINF_SUCCESS;
407 //create DataModel here and fill it from the response data
408 DataParser *dp = NULL;
409 vrc = aCC.createDataParser(&dp);
410 if (RT_SUCCESS(vrc))
411 vrc = dp->parseData(aCC);
412 ////////////////////////////////
413 //maybe partially work with data here
414 ////////////////////////////////
415
416 delete dp;
417
418 return vrc;
419}
420
421int CloudClient::i_getCommandById(const com::Guid &aId, CloudCommandCl **aCC)
422{
423 int vrc = VINF_SUCCESS;
424 std::map <com::Guid, CloudCommandCl*>::iterator cit = mCloudCommandMap.find(aId);
425 if (cit != mCloudCommandMap.end())
426 {
427 *aCC = cit->second;
428// CloudCommandCl * lCC = cit->second->copy();
429// aCC = *lCC;
430 }
431 else
432 vrc = VERR_NOT_FOUND;
433
434 return vrc;
435}
436
437HRESULT CloudClient::getCommandParameterNames(CloudCommand_T aCloudCommand,
438 std::vector<com::Utf8Str> &aParameterNames)
439{
440 LogRel(("CloudClient::getCommandParameterNames()\n"));
441 RT_NOREF(aCloudCommand, aParameterNames);
442 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
443 return hrc;
444}
445
446HRESULT CloudClient::getCommandParameterProperties(const com::Utf8Str &aParameterName,
447 com::Utf8Str &aParameterType,
448 com::Utf8Str &aParameterDesc,
449 std::vector<com::Utf8Str> &aParameterValues)
450{
451 LogRel(("CloudClient::getCommandParameterProperties()\n"));
452 RT_NOREF(aParameterName, aParameterType, aParameterDesc, aParameterValues);
453 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
454 return hrc;
455}
456
457HRESULT CloudClient::getCommandParameters(CloudCommand_T aCloudCommand, com::Utf8Str &aJsonString)
458{
459 LogRel(("CloudClient::getCommandParameters()\n"));
460 RT_NOREF(aCloudCommand, aJsonString);
461 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
462 return hrc;
463}
464
465HRESULT CloudClient::setCommandParameters(const com::Guid &aId,
466 const std::vector<com::Utf8Str> &aNames,
467 const std::vector<com::Utf8Str> &aValues)
468{
469 HRESULT hrc = S_OK;
470 std::vector<com::Utf8Str> parameterNames;
471 std::map <com::Guid, CloudCommandCl*>::iterator it = mCloudCommandMap.find(aId);
472 if (it !=mCloudCommandMap.end())
473 {
474 hrc = getCommandParameterNames(it->second->mCommand, parameterNames);
475 std::vector<com::Utf8Str>::const_iterator cit = aNames.begin();
476 for (size_t i=0 ; i<aNames.size() && i<aValues.size(); ++i)
477 {
478 std::vector<com::Utf8Str>::iterator fit = find(parameterNames.begin(), parameterNames.end(), *cit);
479 if (fit != parameterNames.end())
480 {
481 it->second->mParameters[aNames[i]] = aValues[i];
482 }
483 }
484 }
485 return hrc;
486}
487
488HRESULT CloudClient::getCommandsForOperation(CloudOperation_T aCloudOperation,
489 BOOL aPrep,
490 std::vector<CloudCommand_T> &aCloudCommands)
491{
492 LogRel(("CloudClient::getCommandsforOperation()\n"));
493 RT_NOREF(aCloudOperation, aPrep, aCloudCommands);
494 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
495 return hrc;
496}
497
498HRESULT CloudClient::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString)
499{
500 LogRel(("CloudClient::getOperationParameters()\n"));
501 RT_NOREF(aCloudOperation, aJsonString);
502 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
503 return hrc;
504}
505
506int CloudClient::i_getCommandParameterNames(const CloudCommandCl &aCC,
507 std::vector<com::Utf8Str> &aParameterNames)
508{
509 LogRel(("Enter CloudClient::i_getCommandParameterNames()\n"));
510 int vrc = VINF_SUCCESS;
511 std::vector<com::Utf8Str> localParameterNames;
512 localParameterNames.reserve(20);
513 vrc = aCC.getParameterNames(localParameterNames);
514// vrc = aCC.mUsedAPI->getCommandParameterNames(&aCC, aParameterNames);
515 if (RT_FAILURE(vrc))
516 vrc = VERR_NOT_FOUND;
517 else
518 {
519 size_t vecSize = localParameterNames.size();
520 for (size_t i=0;i<vecSize;++i)
521 {
522 aParameterNames.push_back(localParameterNames.at(i));
523 }
524 }
525 return vrc;
526}
527
528int CloudClient::i_isSimpleCommand(const CloudCommandCl &aCC, bool &fSimple)
529{
530 LogRel(("CloudClient::i_isSimpleCommand()\n"));
531 RT_NOREF(aCC, fSimple);
532 return VERR_NOT_IMPLEMENTED;
533}
534
535//int CloudClient::i_findCommandById(const com::Guid &aId, CloudCommandCl &res)
536//{
537// HRESULT hrc = S_OK;
538// std::map <com::Guid, CloudCommandCl*>::const_iterator it = mCloudCommandMap.find(aId);
539// if (it !=mCloudCommandMap.end())
540// res = *(it->second);
541// else
542// hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Could not find the command object"));
543// return hrc;
544//}
545
546int CloudClient::i_queryAPIForCommand(CloudCommand_T aCommand, CloudAPI** apiObj)
547{
548 LogRel(("CloudClient::queryAPIForCommand()\n"));
549 RT_NOREF(aCommand, apiObj);
550 return VERR_NOT_IMPLEMENTED;
551}
552
553HRESULT CloudClient::i_getSupportedAPIs(std::list<Utf8Str> &apiNames)
554{
555 LogRel(("CloudClient::getSupportedAPIs()\n"));
556 RT_NOREF(apiNames);
557 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
558 return hrc;
559}
560
561HRESULT CloudClient::i_queryAPI(const Utf8Str &apiName, CloudAPI **apiObj)
562{
563 LogRel(("CloudClient::queryAPI()\n"));
564 RT_NOREF(apiName, apiObj);
565 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
566 return hrc;
567}
568
569
570int CloudClient::i_queryAPINameForCommand(CloudCommand_T aCommand, Utf8Str &apiName)
571{
572 LogRel(("CloudClient::i_queryAPINameForCommand()\n"));
573 RT_NOREF(aCommand, apiName);
574 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
575 return hrc;
576}
577
578HRESULT CloudClient::i_setUpProgress(ComObjPtr<Progress> &pProgress,
579 const Utf8Str &strDescription,
580 ULONG aOperations)
581{
582 HRESULT hrc;
583
584 /* Create the progress object */
585 pProgress.createObject();
586
587 ULONG ulTotalOperationsWeight = 100;
588 ULONG ulFirstOperationWeight = ulTotalOperationsWeight/aOperations;
589 hrc = pProgress->init(mParent, static_cast<ICloudClient*>(this),
590 Bstr(strDescription).raw(),
591 TRUE /* aCancelable */,
592 aOperations,
593 ulTotalOperationsWeight,
594 Bstr(strDescription).raw(),
595 ulFirstOperationWeight);
596 return hrc;
597}
598
599////////////////////////////////////////////////////////////////////////////////
600//
601// CloudClientOCI implementation
602//
603////////////////////////////////////////////////////////////////////////////////
604
605CloudClientOCI::CloudClientOCI()
606{
607 LogRel(("CloudClientOCI::CloudClientOCI()\n"));
608}
609
610CloudClientOCI::~CloudClientOCI()
611{
612 LogRel(("CloudClientOCI::~CloudClientOCI()\n"));
613}
614
615HRESULT CloudClientOCI::initCloudClient(CloudUserProfiles *aProfiles,
616 VirtualBox *aParent,
617 CloudProviderId_T aCloudProvider,
618 const com::Utf8Str &aProfileName)
619{
620 HRESULT hrc = S_OK;
621 try
622 {
623 hrc = CloudClient::initCloudClient(aProfiles, aParent, aCloudProvider, aProfileName);
624 if (SUCCEEDED(hrc))
625 {
626 std::list<Utf8Str> apiNames;
627 i_getSupportedAPIs(apiNames);
628 std::list<Utf8Str>::const_iterator cit = apiNames.begin();
629 while (cit!=apiNames.end())
630 {
631 mCloudAPIInstanceMap[*cit] = NULL;
632 ++cit;
633 }
634 }
635 }
636 catch (HRESULT arc)
637 {
638 hrc = arc;
639 LogRel(("Get cought an exception %d\n", hrc));
640 }
641
642 return hrc;
643}
644
645HRESULT CloudClientOCI::getCommandsForOperation(CloudOperation_T aCloudOperation,
646 BOOL aPrep,
647 std::vector<CloudCommand_T> &aCloudCommands)
648{
649 HRESULT hrc = S_OK;
650 if (aCloudOperation == CloudOperation_exportVM)
651 {
652 if (aPrep)
653 {
654 aCloudCommands.push_back(CloudCommand_listAvailabilityDomains);
655 aCloudCommands.push_back(CloudCommand_listShapes);
656 aCloudCommands.push_back(CloudCommand_getNamespace);
657 aCloudCommands.push_back(CloudCommand_listBuckets);
658 aCloudCommands.push_back(CloudCommand_listNetworks);
659 }
660 else
661 {
662 aCloudCommands.push_back(CloudCommand_uploadFile);
663 aCloudCommands.push_back(CloudCommand_importImage);
664 aCloudCommands.push_back(CloudCommand_launchInstance);
665 }
666 }
667
668 return hrc;
669}
670
671int CloudClientOCI::i_isSimpleCommand(const CloudCommandCl &aCC, bool &fSimple)
672{
673 int vrc = S_OK;
674 bool res = false;
675 std::vector<com::Utf8Str> paramNames;
676 HRESULT hrc = getCommandParameterNames(aCC.mCommand, paramNames);
677 if (SUCCEEDED(hrc))
678 {
679 if (paramNames.empty())
680 res = true;
681 }
682 else
683 vrc = VERR_NOT_FOUND;
684
685 fSimple = res;
686
687 return vrc;
688}
689
690int CloudClientOCI::i_queryAPIForCommand(CloudCommand_T aCommand, CloudAPI **apiObj)
691{
692 int vrc = VINF_SUCCESS;
693 CloudAPI *newCloudAPI = NULL;
694
695 try
696 {
697 switch (aCommand)
698 {
699 case CloudCommand_createInstance:
700 case CloudCommand_launchInstance:
701 case CloudCommand_pauseInstance:
702 case CloudCommand_stopInstance:
703 case CloudCommand_deleteInstance:
704 case CloudCommand_getInstanceProperties:
705 case CloudCommand_listInstances:
706 case CloudCommand_listShapes:
707 case CloudCommand_listNetworks:
708 case CloudCommand_importImage:
709 newCloudAPI = new OCICompute();
710 break;
711 case CloudCommand_uploadFile:
712 case CloudCommand_downloadObject:
713 case CloudCommand_deleteObject:
714 case CloudCommand_getObjectProperties:
715 case CloudCommand_listObjects:
716 case CloudCommand_listBuckets:
717 case CloudCommand_getNamespace:
718 newCloudAPI = new OCIObjectStorage();
719 break;
720 case CloudCommand_listRegions:
721 case CloudCommand_listCompartments:
722 case CloudCommand_listAvailabilityDomains:
723 newCloudAPI = new OCIIAM();
724 case CloudCommand_Unknown:
725 default:
726 break;
727 }
728 }
729 catch (int arc)
730 {
731 vrc = arc;
732 LogRel(("Get cought an exception %d\n", vrc));
733 }
734
735 *apiObj = newCloudAPI;
736 return vrc;
737}
738
739HRESULT CloudClientOCI::i_getSupportedAPIs(std::list<Utf8Str> &apiNames)
740{
741 HRESULT hrc = S_OK;
742 apiNames.push_back("compute");
743 apiNames.push_back("object storage");
744 apiNames.push_back("iam");
745 return hrc;
746}
747
748HRESULT CloudClientOCI::i_queryAPI(const Utf8Str &apiName, CloudAPI **apiObj)
749{
750 HRESULT hrc = S_OK;
751 CloudAPI *newCloudAPI = NULL;
752 try
753 {
754 if (apiName == "compute")
755 newCloudAPI = new OCICompute();
756 else if (apiName == "object storage")
757 newCloudAPI = new OCIObjectStorage();
758 else if (apiName == "iam")
759 newCloudAPI = new OCIIAM();
760 }
761 catch (HRESULT arc)
762 {
763 hrc = arc;
764 LogRel(("Get cought an exception %d\n", hrc));
765 }
766
767 *apiObj = newCloudAPI;
768 return hrc;
769}
770
771int CloudClientOCI::i_queryAPINameForCommand(CloudCommand_T aCommand, Utf8Str &apiName)
772{
773 int vrc = VINF_SUCCESS;
774 switch (aCommand)
775 {
776 case CloudCommand_createInstance:
777 case CloudCommand_launchInstance:
778 case CloudCommand_pauseInstance:
779 case CloudCommand_stopInstance:
780 case CloudCommand_deleteInstance:
781 case CloudCommand_getInstanceProperties:
782 case CloudCommand_listInstances:
783 case CloudCommand_listShapes:
784 case CloudCommand_listNetworks:
785 case CloudCommand_importImage:
786 apiName = "compute";
787 break;
788 case CloudCommand_uploadFile:
789 case CloudCommand_downloadObject:
790 case CloudCommand_deleteObject:
791 case CloudCommand_getObjectProperties:
792 case CloudCommand_listObjects:
793 case CloudCommand_listBuckets:
794 case CloudCommand_getNamespace:
795 apiName = "object storage";
796 break;
797 case CloudCommand_listRegions:
798 case CloudCommand_listCompartments:
799 case CloudCommand_listAvailabilityDomains:
800 apiName = "iam";
801 break;
802 case CloudOperation_Unknown:
803 default:
804 vrc = VERR_NOT_IMPLEMENTED;
805 break;
806 }
807
808 return vrc;
809}
810
811HRESULT CloudClientOCI::getCommandParameterNames(CloudCommand_T aCloudCommand,
812 std::vector<com::Utf8Str> &aParameterNames)
813{
814 RT_NOREF(aCloudCommand, aParameterNames);
815 HRESULT hrc = S_OK;
816// switch (aCloudCommand)
817// {
818// case CloudCommand_createInstance:
819// case CloudCommand_launchInstance:
820// aParameterNames.push_back(paramsNames[0]);
821// aParameterNames.push_back(paramsNames[1]);
822// aParameterNames.push_back(paramsNames[2]);
823// aParameterNames.push_back(paramsNames[3]);
824// aParameterNames.push_back(paramsNames[4]);
825// aParameterNames.push_back(paramsNames[5]);
826// aParameterNames.push_back(paramsNames[6]);
827// break;
828// case CloudCommand_pauseInstance:
829// case CloudCommand_stopInstance:
830// case CloudCommand_deleteInstance:
831// case CloudCommand_getInstanceProperties:
832// aParameterNames.push_back(paramsNames[7]);
833// break;
834// //only compartment Id is needed
835// case CloudCommand_listInstances:
836// case CloudCommand_listRegions:
837// case CloudCommand_listShapes:
838// case CloudCommand_listNetworks:
839// case CloudCommand_listBuckets:
840// break;
841// case CloudCommand_importImage:
842// aParameterNames.push_back(paramsNames[8]);
843// break;
844// case CloudCommand_uploadFile:
845// aParameterNames.push_back(paramsNames[9]);
846// aParameterNames.push_back(paramsNames[3]);
847// break;
848// case CloudCommand_downloadObject:
849// case CloudCommand_deleteObject:
850// case CloudCommand_getObjectProperties:
851// aParameterNames.push_back(paramsNames[10]);
852// aParameterNames.push_back(paramsNames[3]);
853// break;
854// case CloudCommand_listObjects:
855// aParameterNames.push_back(paramsNames[3]);
856// break;
857// case CloudCommand_Unknown:
858// default:
859// hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Unknown cloud command %d"), aCloudCommand);
860// break;
861// }
862
863 return hrc;
864}
865
866HRESULT CloudClientOCI::getCommandParameters(CloudCommand_T aCloudCommand, com::Utf8Str &aJsonString)
867{
868 LogRel(("CloudClientOCI::getOperationParameters: %d\n", aCloudCommand));
869 RT_NOREF(aJsonString);
870 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
871 return hrc;
872}
873
874static Utf8Str strExportParametersToOCI = "{\n"
875"\t""\"Shape of instance\": {\n"
876"\t""\t""\"type\": 27,\n"
877"\t""\t""\"items\": [\n"
878"\t""\t""\t""\"VM.Standard1.1\",\n"
879"\t""\t""\t""\"VM.Standard1.2\",\n"
880"\t""\t""\t""\"VM.Standard1.4\",\n"
881"\t""\t""\t""\"VM.Standard1.8\",\n"
882"\t""\t""\t""\"VM.Standard1.16\"\n"
883"\t""\t""]\n"
884"\t""},\n"
885"\t""\"Availability domain\": {\n"
886"\t""\t""\"type\": 28,\n"
887"\t""\t""\"items\": [\n"
888"\t""\t""\t""\"ergw:US-ASHBURN-AD-1\",\n"
889"\t""\t""\t""\"ergw:US-ASHBURN-AD-2\",\n"
890"\t""\t""\t""\"ergw:US-ASHBURN-AD-3\"\n"
891"\t""\t""]\n"
892"\t""},\n"
893"\t""\"Disk size\": {\n"
894"\t""\t""\"type\": 29,\n"
895"\t""\t""\"min\": 10,\n"
896"\t""\t""\"max\": 300,\n"
897"\t""\t""\"unit\": \"GB\"\n"
898"\t""},\n"
899"\t""\"Bucket\": {\n"
900"\t""\t""\"type\": 30,\n"
901"\t""\t""\"items\": [\n"
902"\t""\t""\t""\"temporarly-bucket-python-ubuntu-14-x64-server\",\n"
903"\t""\t""\t""\"temporarly-bucket-python-un-ubuntu\",\n"
904"\t""\t""\t""\"test_cpp_bucket\",\n"
905"\t""\t""\t""\"vbox_test_bucket_1\"\n"
906"\t""\t""]\n"
907"\t""},\n"
908"\t""\"Virtual Cloud Network\": {\n"
909"\t""\t""\"type\": 31,\n"
910"\t""\t""\"items\": [\n"
911"\t""\t""\t""\"vcn-scoter\",\n"
912"\t""\t""\t""\"vcn20180510154500\",\n"
913"\t""\t""\t""\"vcn_spider\"\n"
914"\t""\t""]\n"
915"\t""},\n"
916"\t""\"Public IP address\": {\n"
917"\t""\t""\"type\": 32,\n"
918"\t""\t""\"bool\": true\n"
919"\t""}\n"
920"}";
921
922static const char* listAvDomain = "[\n"
923"\t{\n"
924"\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n"
925"\t\t\"name\": \"ergw:US-ASHBURN-AD-1\"\n"
926"\t},\n"
927"\t{\n"
928"\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n"
929"\t\t\"name\": \"ergw:US-ASHBURN-AD-2\"\n"
930"\t},\n"
931"\t{\n"
932"\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n"
933"\t\t\"name\": \"ergw:US-ASHBURN-AD-3\"\n"
934"\t}\n"
935"]\n";
936
937static Utf8Str strListAvDomain(listAvDomain);
938
939static const char* listShape = "[\n"
940"\t{\n"
941"\t\t\"shape\": \"VM.Standard1.1\"\n"
942"\t},\n"
943"\t{\n"
944"\t\t\"shape\": \"VM.Standard1.2\"\n"
945"\t},\n"
946"\t{\n"
947"\t\t\"shape\": \"VM.Standard1.4\"\n"
948"\t},\n"
949"\t{\n"
950"\t\t\"shape\": \"VM.Standard1.8\"\n"
951"\t},\n"
952"\t{\n"
953"\t\t\"shape\": \"VM.Standard1.16\"\n"
954"\t}\n"
955"]\n";
956
957static Utf8Str strListShape(listShape);
958
959static const char* namespaceName = "{\n"
960"\t\"ovm\"\n"
961"}\n";
962
963static Utf8Str strNamespaceName(namespaceName);
964
965static const char* listBucket = "[\n"
966"\t{\n"
967"\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n"
968"\t\t\"createdBy\": \"ocid1.user.oc1..aaaaaaaa73t54ewmkiti4i4bmsxyjfwgiujhuf4hnhkvipgmmukkgextxujq\",\n"
969"\t\t\"definedTags\": null,\n"
970"\t\t\"etag\": \"06262c11-a6b3-44a1-9ccd-6d062dcf73cb\",\n"
971"\t\t\"freeformTags\": null,\n"
972"\t\t\"name\": \"temporarly-bucket-python-ubuntu-14-x64-server\",\n"
973"\t\t\"namespace\": \"ovm\",\n"
974"\t\t\"timeCreated\": \"2018-05-15T11:23:05.653000+00:00\"\n"
975"\t},\n"
976"\t{\n"
977"\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n"
978"\t\t\"createdBy\": \"ocid1.user.oc1..aaaaaaaa73t54ewmkiti4i4bmsxyjfwgiujhuf4hnhkvipgmmukkgextxujq\",\n"
979"\t\t\"definedTags\": null,\n"
980"\t\t\"etag\": \"036be210-3021-4598-b707-c82e5c5cfa08\",\n"
981"\t\t\"freeformTags\": null,\n"
982"\t\t\"name\": \"temporarly-bucket-python-un-ubuntu\",\n"
983"\t\t\"namespace\": \"ovm\",\n"
984"\t\t\"timeCreated\": \"2018-05-10T12:30:40.376000+00:00\"\n"
985"\t},\n"
986"\t{\n"
987"\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n"
988"\t\t\"createdBy\": \"ocid1.user.oc1..aaaaaaaas2vfq7jfhct4dto4uk5myhripw5cdvnz4ddgu44buv4fcxgafhhq\",\n"
989"\t\t\"definedTags\": null,\n"
990"\t\t\"etag\": \"b7c9f373-36be-4228-b505-0a46f07b4c41\",\n"
991"\t\t\"freeformTags\": null,\n"
992"\t\t\"name\": \"test_cpp_bucket\",\n"
993"\t\t\"namespace\": \"ovm\",\n"
994"\t\t\"timeCreated\": \"2018-07-18T15:04:31.285000+00:00\"\n"
995"\t},\n"
996"\t{\n"
997"\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n"
998"\t\t\"createdBy\": \"ocid1.user.oc1..aaaaaaaat47uhcg5ucbznrknalr2ta2s35flxbpfwly74rzp2ivj3fd4sy3a\",\n"
999"\t\t\"definedTags\": null,\n"
1000"\t\t\"etag\": \"5a4477d9-8fc4-401f-994e-0e940b1dfb84\",\n"
1001"\t\t\"freeformTags\": null,\n"
1002"\t\t\"name\": \"vbox_test_bucket_1\",\n"
1003"\t\t\"namespace\": \"ovm\",\n"
1004"\t\t\"timeCreated\": \"2018-05-04T17:56:20.222000+00:00\"\n"
1005"\t}\n"
1006"]\n";
1007
1008static Utf8Str strListBucket(listBucket);
1009
1010static const char* listVcn = "[\n"
1011"\t{\n"
1012"\t\t\"cidr-block\": \"192.168.0.0/24\",\n"
1013"\t\t\"compartment-id\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n"
1014"\t\t\"default-dhcp-options-id\": \"ocid1.dhcpoptions.oc1.iad.aaaaaaaadubfpdssid2f3iewwnq2e2iudguqx4vnn5uivlvwp3uuoydxgq4q\",\n"
1015"\t\t\"default-route-table-id\": \"ocid1.routetable.oc1.iad.aaaaaaaajiksnjaqmrzqy2dfiijyxny4qnk65hyfr72cuulaeteis363w5lq\",\n"
1016"\t\t\"default-security-list-id\": \"ocid1.securitylist.oc1.iad.aaaaaaaagzuwh3lxnbhmnl6wtuycynwoxoekl62fttg4tqvwh7apfbuedixq\",\n"
1017"\t\t\"defined-tags\": {},\n"
1018"\t\t\"display-name\": \"vcn-scoter\",\n"
1019"\t\t\"dns-label\": \"vcnscoter\",\n"
1020"\t\t\"freeform-tags\": {},\n"
1021"\t\t\"id\": \"ocid1.vcn.oc1.iad.aaaaaaaayytm3gse3cr7wqq56zjatcak2wk4prb26sh3s3egkz2azknc5d6q\",\n"
1022"\t\t\"lifecycle-state\": \"AVAILABLE\",\n"
1023"\t\t\"time-created\": \"2018-06-14T16:29:52.788000+00:00\",\n"
1024"\t\t\"vcn-domain-name\": \"vcnscoter.oraclevcn.com\"\n"
1025"\t},\n"
1026"\t{\n"
1027"\t\t\"cidr-block\": \"10.8.0.0/16\",\n"
1028"\t\t\"compartment-id\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n"
1029"\t\t\"default-dhcp-options-id\": \"ocid1.dhcpoptions.oc1.iad.aaaaaaaasqjcnaqo2f7wgovvnnajgrcfinnoifqt3wc2xc5rdd76yqn3pp3q\",\n"
1030"\t\t\"default-route-table-id\": \"ocid1.routetable.oc1.iad.aaaaaaaavzwgctg35rfqr44st5d7endapdyelnndbo6nul63i4qec7ptdjna\",\n"
1031"\t\t\"default-security-list-id\": \"ocid1.securitylist.oc1.iad.aaaaaaaasb5al7waxkyb4rmuky3qwym2sb4ctpphqzxbigh6e2rkfj5zgxqq\",\n"
1032"\t\t\"defined-tags\": {},\n"
1033"\t\t\"display-name\": \"vcn_spider\",\n"
1034"\t\t\"dns-label\": \"vcnspider\",\n"
1035"\t\t\"freeform-tags\": {},\n"
1036"\t\t\"id\": \"ocid1.vcn.oc1.iad.aaaaaaaa4mhghya6ztii7par7v2o3v2il5nbbbx32benobjv3wlcs2ekpyaq\",\n"
1037"\t\t\"lifecycle-state\": \"AVAILABLE\",\n"
1038"\t\t\"time-created\": \"2018-06-07T14:46:10.855000+00:00\",\n"
1039"\t\t\"vcn-domain-name\": \"vcnspider.oraclevcn.com\"\n"
1040"\t},\n"
1041"\t{\n"
1042"\t\t\"cidr-block\": \"10.0.0.0/16\",\n"
1043"\t\t\"compartment-id\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n"
1044"\t\t\"default-dhcp-options-id\": \"ocid1.dhcpoptions.oc1.iad.aaaaaaaao5tkhev2vqvpyzrpvzwiqbxz6w4kolcfdoo57xxktehv3qpv6hza\",\n"
1045"\t\t\"default-route-table-id\": \"ocid1.routetable.oc1.iad.aaaaaaaantab6kld6b2wcxgv5rs5abmg4tmd5ok274emejfnofl744pignva\",\n"
1046"\t\t\"default-security-list-id\": \"ocid1.securitylist.oc1.iad.aaaaaaaashi4gkt35wyfwozh5vsbxi4e76leca27xkgun42n4aorgg5qtfuq\",\n"
1047"\t\t\"defined-tags\": {},\n"
1048"\t\t\"display-name\": \"vcn20180510154500\",\n"
1049"\t\t\"dns-label\": \"vcn0510154459\",\n"
1050"\t\t\"freeform-tags\": {},\n"
1051"\t\t\"id\": \"ocid1.vcn.oc1.iad.aaaaaaaaaxetjzokkuahch46aglb4peltzto67tihc73mmako6o2ct4yk75a\",\n"
1052"\t\t\"lifecycle-state\": \"AVAILABLE\",\n"
1053"\t\t\"time-created\": \"2018-05-10T15:45:00.579000+00:00\",\n"
1054"\t\t\"vcn-domain-name\": \"vcn0510154459.oraclevcn.com\"\n"
1055"\t}\n"
1056"]\n";
1057
1058static Utf8Str strListVcn(listVcn);
1059
1060//HRESULT CloudClientOCI::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString)
1061//{
1062// LogRel(("CloudClientOCI::getOperationParameters: %d\n", aCloudOperation));
1063// HRESULT hrc = S_OK;
1064// if (aCloudOperation == CloudOperation_exportVM)
1065// aJsonString = strExportParametersToOCI;
1066// else
1067// hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
1068// return hrc;
1069//}
1070
1071HRESULT CloudClientOCI::getOperationParameters(CloudOperation_T aCloudOperation,
1072 com::Utf8Str &aJsonString)
1073// ComPtr<IProgress> &aProgress)
1074{
1075 LogRel(("CloudClientOCI::getOperationParameters: %d\n", aCloudOperation));
1076 RT_NOREF(aJsonString);
1077 HRESULT hrc = S_OK;
1078 int vrc = VINF_SUCCESS;
1079
1080 std::vector<CloudCommand_T> commandList;
1081 hrc = getCommandsForOperation(aCloudOperation, true, commandList);
1082 if (FAILED(hrc))
1083 return setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Commands not found"));
1084
1085 com::Guid firstCommandId;
1086 std::vector<com::Guid> commandIDs;
1087 for (size_t i=0;i<commandList.size();++i)
1088 {
1089 com::Guid cId;
1090 vrc = i_createCommand(commandList[i], cId);
1091 if (RT_SUCCESS(vrc))
1092 {
1093
1094 //remember first command Id for getting the command description for Progress
1095 if (i==0)
1096 firstCommandId = cId;
1097
1098 commandIDs.push_back(cId);
1099 LogRel(("Command %d have got UUID %s\n", commandList[i], cId.toString().c_str()));
1100 }
1101 else
1102 {
1103 setErrorBoth(E_FAIL, vrc, tr("Creation of command %d failed."), commandList[i]);
1104 break;
1105 }
1106 }
1107
1108 if (FAILED(hrc))
1109 return hrc;
1110
1111 std::map<Utf8Str, Utf8Str> paramNameValueMap;
1112
1113 //Setup Progress object here
1114 ComObjPtr<Progress> progress;
1115 ComPtr<IProgress> aProgress;
1116 {
1117 CloudCommandCl *cc = NULL;
1118 vrc = i_getCommandById(firstCommandId, &cc);
1119 if (RT_SUCCESS(vrc))
1120 {
1121 paramNameValueMap = cc->mParameters;
1122 Utf8Str strDesc = cc->getDescription();
1123 hrc = i_setUpProgress(progress, strDesc, (ULONG)commandList.size());
1124 if (SUCCEEDED(hrc))
1125 /* Return progress to the caller */
1126 progress.queryInterfaceTo(aProgress.asOutParam());
1127 }
1128 else
1129 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Command with Id %s not found"), firstCommandId.toString().c_str());
1130 }
1131
1132 if (FAILED(hrc))
1133 return hrc;
1134
1135 //stores the last command successful response
1136 std::vector<DataModel*> dm;
1137 std::map<Utf8Str, Utf8Str> summaryInfo;
1138 com::Guid lastCommandId;
1139
1140 /*
1141 * STRONG prerequisity: First command MUST BE validated always.
1142 * It means that all needed parameters must be correct or
1143 * the command hasn't any parameters.
1144 */
1145 bool fWeakValidation = false;//validation has two tries, but for the first command there is only one try
1146
1147 for (size_t i=0;i<commandIDs.size();++i)
1148 {
1149 CloudCommandCl *cc = NULL;
1150 vrc = i_getCommandById(commandIDs.at(i), &cc);
1151 if (RT_SUCCESS(vrc) && cc!=NULL)
1152 {
1153 vrc = i_validateCommand(*cc, paramNameValueMap, fWeakValidation);
1154 if (RT_SUCCESS(vrc) && vrc != VINF_TRY_AGAIN)
1155 {
1156// vrc = i_runCommand(*cc, progress);//<---Progress must be passed here
1157 vrc = i_runCommand(*cc);
1158
1159 CloudCommandResult_T commResult = CloudCommandResult_success;
1160 if (RT_SUCCESS(vrc))
1161 {
1162 if (true)
1163 {
1164 switch (cc->mCommand)
1165 {
1166 case CloudCommand_getNamespace:
1167 cc->mResponse.mRaw = strNamespaceName;
1168 break;
1169 case CloudCommand_listAvailabilityDomains:
1170 cc->mResponse.mRaw = strListAvDomain;
1171 break;
1172 case CloudCommand_listNetworks:
1173 cc->mResponse.mRaw = strListVcn;
1174 break;
1175 case CloudCommand_listShapes:
1176 cc->mResponse.mRaw = strListShape;
1177 break;
1178 case CloudCommand_listBuckets:
1179 cc->mResponse.mRaw = strListBucket;
1180 break;
1181 default:
1182 break;
1183 }
1184 }
1185// vrc = i_checkCommandResult(*cc, commResult);
1186// if (RT_SUCCESS(vrc))
1187 {
1188 vrc = i_parseResponse(*cc);
1189// dm = cc->getData();
1190// summaryInfo = cc->getSummary();
1191 lastCommandId = commandIDs.at(i);//remember the last command Id
1192 fWeakValidation = true;//restore weak validation for the next command
1193 }
1194 }
1195 else
1196 {
1197 hrc = setError(E_FAIL, tr("The call of command %d was unsuccessful"), cc->mCommand);
1198 }
1199 LogRel(("Command %d result is %d\n", commandList[i], commResult));
1200 }
1201 else
1202 {
1203 if (RT_FAILURE(vrc))
1204 {
1205 hrc = setErrorBoth(E_FAIL, vrc, tr("Command %d wasn't validated"), commandList[i]);
1206 break;
1207 }
1208
1209 if (vrc == VINF_TRY_AGAIN)
1210 {
1211 LogRel(("Command %d hasn't been validated yet.\n", commandList[i]));
1212 //try to find and extract needed parameters from the last executed command response
1213 //convert summaryInfo into paramNameValueMap (extract from summaryInfo and convert it)
1214 std::vector<com::Utf8Str> paramNames;
1215
1216 vrc = i_getCommandParameterNames(*cc, paramNames);
1217 if (RT_SUCCESS(vrc))
1218 {
1219 CloudCommandCl *lastCC = NULL;
1220 if (lastCommandId.isValid())
1221 {
1222 vrc = i_getCommandById(lastCommandId, &lastCC);
1223 if (RT_SUCCESS(vrc) && lastCC!=NULL)
1224 {
1225 for (size_t j=0;j<paramNames.size();++j)
1226 {
1227 Utf8Str strValue;
1228 vrc = lastCC->findParameter(paramNames.at(j), strValue);
1229 if (RT_SUCCESS(vrc))
1230 paramNameValueMap.insert(make_pair(paramNames.at(j), strValue));
1231 else
1232 {
1233 hrc = setErrorBoth(E_FAIL, vrc,
1234 tr("Command %d wasn't validated"),
1235 commandList[j]);
1236 break;
1237 }
1238 }
1239 }
1240 else
1241 hrc = setErrorBoth(E_FAIL, vrc,
1242 tr("Couldn't find command with Id \"%s\""),
1243 lastCommandId.toString().c_str());
1244 }
1245 else
1246 {
1247 vrc = VERR_INVALID_UUID_FORMAT;
1248 hrc = setErrorBoth(E_FAIL, vrc, tr("Invalid UUID for the command %d "), commandList[i]);
1249 }
1250 }
1251 else
1252 hrc = setErrorBoth(E_FAIL, vrc, tr("Couldn't find command parameter names"));
1253
1254 if (RT_FAILURE(vrc))
1255 {
1256 LogRel(("Command %d hasn't been validated twice. Can't continue.\n", commandList[i]));
1257 break;
1258 }
1259
1260 /*
1261 * Set validation to "Strong"
1262 * and try to validate the command one more time
1263 */
1264 {
1265 fWeakValidation = false;
1266 --i;
1267 }
1268 }
1269 }
1270 }
1271 }
1272
1273 return hrc;
1274}
1275
1276////////////////////////////////////////////////////////////////////////////////
1277//
1278// CloudClientGCP implementation
1279//
1280////////////////////////////////////////////////////////////////////////////////
1281//HRESULT CloudClientGCP::i_getSupportedAPIs(std::list<Utf8Str> &apiNames)
1282//{
1283// HRESULT hrc = S_OK;
1284// apiNames.push_back("compute");
1285// apiNames.push_back("storage");
1286// return hrc;
1287//}
1288//
1289//HRESULT CloudClientGCP::i_queryAPI(const Utf8Str &apiName, CloudAPI* apiObj)
1290//{
1291// HRESULT hrc = S_OK;
1292// try
1293// {
1294// CloudAPI *newCloudAPI = NULL;
1295// if (APIName == "compute")
1296// newCloudAPI = new GCPCompute();
1297// else if (APIName == "storage")
1298// newCloudAPI = new GCPStorage();
1299// apiObj = newCloudAPI;
1300// }
1301// catch (HRESULT arc)
1302// {
1303// hrc = arc;
1304// LogRel(("Get cought an exception %d\n", hrc));
1305// }
1306//
1307// return hrc;
1308//}
1309//
1310//HRESULT CloudClientGCP::i_queryAPINameForCommand(CloudCommand_T aCommand, Utf8Str &apiName)
1311//{
1312// LogRel(("CloudClientGCP::queryAPINameForCommand: %d, %s\n", aCommand, apiName.c_str()));
1313// HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));
1314// return hrc;
1315//}
1316
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette