1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 try:
18 import json
19 except ImportError:
20 import simplejson as json
21
22 import copy
23 import datetime
24 import time
25
26 __docformat__ = "epytext"
27
28 -class Attr(object):
29 """
30 Encapsulates information about an attribute in the JSON encoding of the
31 object. It identifies properties of the attribute such as whether it's
32 read-only, its type, etc.
33 """
34 DATE_FMT = "%Y-%m-%dT%H:%M:%S.%fZ"
35
36 - def __init__(self, atype=None, rw=True, is_api_list=False):
37 self._atype = atype
38 self._is_api_list = is_api_list
39 self.rw = rw
40
41 - def to_json(self, value, preserve_ro):
42 """
43 Returns the JSON encoding of the given attribute value.
44
45 If the value has a 'to_json_dict' object, that method is called. Otherwise,
46 the following values are returned for each input type:
47 - datetime.datetime: string with the API representation of a date.
48 - dictionary: if 'atype' is ApiConfig, a list of ApiConfig objects.
49 - python list: python list (or ApiList) with JSON encoding of items
50 - the raw value otherwise
51 """
52 if hasattr(value, 'to_json_dict'):
53 return value.to_json_dict(preserve_ro)
54 elif isinstance(value, dict) and self._atype == ApiConfig:
55 return config_to_api_list(value)
56 elif isinstance(value, datetime.datetime):
57 return value.strftime(self.DATE_FMT)
58 elif isinstance(value, list) or isinstance(value, tuple):
59 if self._is_api_list:
60 return ApiList(value).to_json_dict()
61 else:
62 return [ self.to_json(x, preserve_ro) for x in value ]
63 else:
64 return value
65
67 """
68 Parses the given JSON value into an appropriate python object.
69
70 This means:
71 - a datetime.datetime if 'atype' is datetime.datetime
72 - a converted config dictionary or config list if 'atype' is ApiConfig
73 - if the attr is an API list, an ApiList with instances of 'atype'
74 - an instance of 'atype' if it has a 'from_json_dict' method
75 - a python list with decoded versions of the member objects if the input
76 is a python list.
77 - the raw value otherwise
78 """
79 if data is None:
80 return None
81
82 if self._atype == datetime.datetime:
83 return datetime.datetime.strptime(data, self.DATE_FMT)
84 elif self._atype == ApiConfig:
85
86
87
88 if not data['items']:
89 return { }
90 first = data['items'][0]
91 return json_to_config(data, len(first) == 2)
92 elif self._is_api_list:
93 return ApiList.from_json_dict(data, resource_root, self._atype)
94 elif isinstance(data, list):
95 return [ self.from_json(resource_root, x) for x in data ]
96 elif hasattr(self._atype, 'from_json_dict'):
97 return self._atype.from_json_dict(data, resource_root)
98 else:
99 return data
100
102 """
103 Subclass that just defines the attribute as read-only.
104 """
105 - def __init__(self, atype=None, is_api_list=False):
106 Attr.__init__(self, atype=atype, rw=False, is_api_list=is_api_list)
107
110 """
111 Checks if the resource_root's API version it at least the given minimum
112 version.
113 """
114 if resource_root.version < min_version:
115 raise Exception("API version %s is required but %s is in use."
116 % (min_version, resource_root.version))
117
118
119 -def call(method, path, ret_type,
120 ret_is_list=False, data=None, params=None, api_version=1):
121 """
122 Generic function for calling a resource method and automatically dealing with
123 serialization of parameters and deserialization of return values.
124
125 @param method: method to call (must be bound to a resource;
126 e.g., "resource_root.get").
127 @param path: the full path of the API method to call.
128 @param ret_type: return type of the call.
129 @param ret_is_list: whether the return type is an ApiList.
130 @param data: Optional data to send as payload to the call.
131 @param params: Optional query parameters for the call.
132 @param api_version: minimum API version for the call.
133 """
134 check_api_version(method.im_self, api_version)
135 if data is not None:
136 data = json.dumps(Attr(is_api_list=True).to_json(data, False))
137 ret = method(path, data=data, params=params)
138 else:
139 ret = method(path, params=params)
140 if ret_type is None:
141 return
142 elif ret_is_list:
143 return ApiList.from_json_dict(ret, method.im_self, ret_type)
144 elif isinstance(ret, list):
145 return [ ret_type.from_json_dict(x, method.im_self) for x in ret ]
146 else:
147 return ret_type.from_json_dict(ret, method.im_self)
148
150 """
151 The BaseApiObject helps with (de)serialization from/to JSON.
152
153 The derived class has two ways of defining custom attributes:
154 - Overwriting the '_ATTRIBUTES' field with the attribute dictionary
155 - Override the _get_attributes() method, in case static initialization of
156 the above field is not possible.
157
158 It's recommended that the _get_attributes() implementation do caching to
159 avoid computing the dictionary on every invocation.
160
161 The derived class's constructor must call the base class's init() static
162 method. All constructor arguments (aside from self and resource_root) must
163 be keywords arguments with default values (typically None), or
164 from_json_dict() will not work.
165 """
166
167 _ATTRIBUTES = { }
168 _WHITELIST = ( '_resource_root', '_attributes' )
169
170 @classmethod
172 """
173 Returns a map of property names to attr instances (or None for default
174 attribute behavior) describing the properties of the object.
175
176 By default, this method will return the class's _ATTRIBUTES field.
177 Classes can override this method to do custom initialization of the
178 attributes when needed.
179 """
180 return cls._ATTRIBUTES
181
182 @staticmethod
183 - def init(obj, resource_root, attrs=None):
184 """
185 Wraper around the real constructor to avoid issues with the 'self'
186 argument. Call like this, from a subclass's constructor:
187
188 - BaseApiObject.init(self, locals())
189 """
190
191
192 str_attrs = { }
193 if attrs:
194 for k, v in attrs.iteritems():
195 if k not in ('self', 'resource_root'):
196 str_attrs[k] = v
197 BaseApiObject.__init__(obj, resource_root, **str_attrs)
198
199 - def __init__(self, resource_root, **attrs):
200 """
201 Initializes internal state and sets all known writable properties of the
202 object to None. Then initializes the properties given in the provided
203 attributes dictionary.
204
205 @param resource_root: API resource object.
206 @param attrs: optional dictionary of attributes to set. This should only
207 contain r/w attributes.
208 """
209 self._resource_root = resource_root
210
211 for name, attr in self._get_attributes().iteritems():
212 object.__setattr__(self, name, None)
213 if attrs:
214 self._set_attrs(attrs, from_json=False)
215
216 - def _set_attrs(self, attrs, allow_ro=False, from_json=True):
217 """
218 Sets all the attributes in the dictionary. Optionally, allows setting
219 read-only attributes (e.g. when deserializing from JSON) and skipping
220 JSON deserialization of values.
221 """
222 for k, v in attrs.iteritems():
223 try:
224 attr = self._check_attr(k, allow_ro)
225 except AttributeError:
226 continue
227 if attr and from_json:
228 v = attr.from_json(self._get_resource_root(), v)
229 object.__setattr__(self, k, v)
230
235
237 if name not in self._get_attributes():
238 raise AttributeError('Invalid property %s for class %s.' %
239 (name, self.__class__.__name__))
240 attr = self._get_attributes()[name]
241 if not allow_ro and attr and not attr.rw:
242 raise AttributeError('Attribute %s of class %s is read only.' %
243 (name, self.__class__.__name__))
244 return attr
245
247 return self._resource_root
248
250 """Copy state from api_obj to this object."""
251 if not isinstance(self, api_obj.__class__):
252 raise ValueError(
253 "Class %s does not derive from %s; cannot update attributes." %
254 (self.__class__, api_obj.__class__))
255
256 for name in self._get_attributes().keys():
257 try:
258 val = getattr(api_obj, name)
259 setattr(self, name, val)
260 except AttributeError, ignored:
261 pass
262
264 dic = { }
265 for name, attr in self._get_attributes().iteritems():
266 if not preserve_ro and attr and not attr.rw:
267 continue
268 try:
269 value = getattr(self, name)
270 if value is not None:
271 if attr:
272 dic[name] = attr.to_json(value, preserve_ro)
273 else:
274 dic[name] = value
275 except AttributeError:
276 pass
277 return dic
278
280 """
281 Default implementation of __str__. Uses the type name and the first
282 attribute retrieved from the attribute map to create the string.
283 """
284 name = self._get_attributes().keys()[0]
285 value = getattr(self, name, None)
286 return "<%s>: %s = %s" % (self.__class__.__name__, name, value)
287
288 @classmethod
290 obj = cls(resource_root)
291 obj._set_attrs(dic, allow_ro=True)
292 return obj
293
295 """
296 A specialization of BaseApiObject that provides some utility methods for
297 resources. This class allows easier serialization / deserialization of
298 parameters and return values.
299 """
300
302 """
303 Returns the minimum API version for this resource. Defaults to 1.
304 """
305 return 1
306
308 """
309 Returns the path to the resource.
310
311 e.g., for a service 'foo' in cluster 'bar', this should return
312 '/clusters/bar/services/foo'.
313 """
314 raise NotImplementedError
315
317 """
318 Raise an exception if the version of the api is less than the given version.
319
320 @param version: The minimum required version.
321 """
322 actual_version = self._get_resource_root().version
323 version = max(version, self._api_version())
324 if actual_version < version:
325 raise Exception("API version %s is required but %s is in use."
326 % (version, actual_version))
327
328 - def _cmd(self, command, data=None, params=None, api_version=1):
329 """
330 Invokes a command on the resource. Commands are expected to be under the
331 "commands/" sub-resource.
332 """
333 return self._post("commands/" + command, ApiCommand,
334 data=data, params=params, api_version=api_version)
335
345
351
352 - def _delete(self, rel_path, ret_type, ret_is_list=False, params=None,
353 api_version=1):
354 return self._call('delete', rel_path, ret_type, ret_is_list, None, params,
355 api_version)
356
357 - def _get(self, rel_path, ret_type, ret_is_list=False, params=None,
358 api_version=1):
359 return self._call('get', rel_path, ret_type, ret_is_list, None, params,
360 api_version)
361
362 - def _post(self, rel_path, ret_type, ret_is_list=False, data=None, params=None,
363 api_version=1):
364 return self._call('post', rel_path, ret_type, ret_is_list, data, params,
365 api_version)
366
367 - def _put(self, rel_path, ret_type, ret_is_list=False, data=None, params=None,
368 api_version=1):
369 return self._call('put', rel_path, ret_type, ret_is_list, data, params,
370 api_version)
371
372 - def _call(self, method, rel_path, ret_type, ret_is_list=False, data=None,
373 params=None, api_version=1):
374 path = self._path()
375 if rel_path:
376 path += '/' + rel_path
377 return call(getattr(self._get_resource_root(), method),
378 path,
379 ret_type,
380 ret_is_list,
381 data,
382 params,
383 api_version)
384
386 """A list of some api object"""
387 LIST_KEY = "items"
388
389 - def __init__(self, objects, resource_root=None, **attrs):
393
395 return "<ApiList>(%d): [%s]" % (
396 len(self.objects),
397 ", ".join([str(item) for item in self.objects]))
398
404
407
410
413
415 return self.objects.__getslice__(i, j)
416
417 @classmethod
436
438 _ATTRIBUTES = {
439 'hostId' : None,
440 }
441
442 - def __init__(self, resource_root, hostId=None):
444
446 return "<ApiHostRef>: %s" % (self.hostId)
447
449 _ATTRIBUTES = {
450 'clusterName' : None,
451 'serviceName' : None,
452 'peerName' : None,
453 }
454
455 - def __init__(self, resource_root, serviceName=None, clusterName=None,
456 peerName=None):
458
460 _ATTRIBUTES = {
461 'clusterName' : None,
462 }
463
464 - def __init__(self, resource_root, clusterName = None):
466
468 _ATTRIBUTES = {
469 'clusterName' : None,
470 'serviceName' : None,
471 'roleName' : None,
472 }
473
474 - def __init__(self, resource_root, serviceName=None, roleName=None,
475 clusterName=None):
477
479 _ATTRIBUTES = {
480 'roleConfigGroupName' : None,
481 }
482
483 - def __init__(self, resource_root, roleConfigGroupName=None):
485
487 SYNCHRONOUS_COMMAND_ID = -1
488
489 @classmethod
491 if not cls.__dict__.has_key('_ATTRIBUTES'):
492 cls._ATTRIBUTES = {
493 'id' : ROAttr(),
494 'name' : ROAttr(),
495 'startTime' : ROAttr(datetime.datetime),
496 'endTime' : ROAttr(datetime.datetime),
497 'active' : ROAttr(),
498 'success' : ROAttr(),
499 'resultMessage' : ROAttr(),
500 'clusterRef' : ROAttr(ApiClusterRef),
501 'serviceRef' : ROAttr(ApiServiceRef),
502 'roleRef' : ROAttr(ApiRoleRef),
503 'hostRef' : ROAttr(ApiHostRef),
504 'children' : ROAttr(ApiCommand, is_api_list=True),
505 'parent' : ROAttr(ApiCommand),
506 'resultDataUrl' : ROAttr(),
507 'canRetry' : ROAttr(),
508 }
509 return cls._ATTRIBUTES
510
512 return "<ApiCommand>: '%s' (id: %s; active: %s; success: %s)" % (
513 self.name, self.id, self.active, self.success)
514
516 return '/commands/%d' % self.id
517
529
530 - def wait(self, timeout=None):
531 """
532 Wait for command to finish.
533
534 @param timeout: (Optional) Max amount of time (in seconds) to wait. Wait
535 forever by default.
536 @return: The final ApiCommand object, containing the last known state.
537 The command may still be running in case of timeout.
538 """
539 if self.id == ApiCommand.SYNCHRONOUS_COMMAND_ID:
540 return self
541
542 SLEEP_SEC = 5
543
544 if timeout is None:
545 deadline = None
546 else:
547 deadline = time.time() + timeout
548
549 while True:
550 cmd = self.fetch()
551 if not cmd.active:
552 return cmd
553
554 if deadline is not None:
555 now = time.time()
556 if deadline < now:
557 return cmd
558 else:
559 time.sleep(min(SLEEP_SEC, deadline - now))
560 else:
561 time.sleep(SLEEP_SEC)
562
563
576
586
592
604
610 """Metric reading data."""
611
612 _ATTRIBUTES = {
613 'timestamp' : ROAttr(datetime.datetime),
614 'value' : ROAttr(),
615 }
616
619
635
641 _ATTRIBUTES = {
642 'name' : ROAttr(),
643 'type' : ROAttr(),
644 'parent' : ROAttr(),
645 'startTime' : ROAttr(),
646 'finishTime' : ROAttr(),
647 'id' : ROAttr(),
648 'status' : ROAttr(),
649 'user' : ROAttr(),
650 'group' : ROAttr(),
651 'inputDir' : ROAttr(),
652 'outputDir' : ROAttr(),
653 'mapper' : ROAttr(),
654 'combiner' : ROAttr(),
655 'reducer' : ROAttr(),
656 'queueName' : ROAttr(),
657 'schedulerPriority' : ROAttr(),
658 }
659
662
664 return "<ApiActivity>: %s (%s)" % (self.name, self.status)
665
666
667
668
669
670 -class ApiCmPeer(BaseApiObject):
671 _ATTRIBUTES = {
672 'name' : None,
673 'url' : None,
674 'username' : None,
675 'password' : None,
676 'type' : None,
677 'clouderaManagerCreatedUser' : None,
678 }
679
681 return "<ApiPeer>: %s (%s)" % (self.name, self.url)
682
688
696
698 _ATTRIBUTES = {
699 'sourceService' : Attr(ApiServiceRef),
700 'sourcePath' : None,
701 'destinationPath' : None,
702 'mapreduceServiceName' : None,
703 'userName' : None,
704 'sourceUser' : None,
705 'numMaps' : None,
706 'dryRun' : None,
707 'bandwidthPerMap' : None,
708 'logPath' : None,
709 'schedulerPoolName' : None,
710 'abortOnError' : None,
711 'preservePermissions' : None,
712 'preserveBlockSize' : None,
713 'preserveReplicationCount' : None,
714 'removeMissingFiles' : None,
715 'skipChecksumChecks' : None,
716 'skipListingChecksumChecks' : None,
717 'skipTrash' : None,
718 'replicationStrategy' : None,
719 'preserveXAttrs' : None,
720 'exclusionFilters' : None,
721 'raiseSnapshotDiffFailures' : None,
722 }
723
735
737 _ATTRIBUTES = {
738 'progress' : ROAttr(),
739 'counters' : ROAttr(),
740 'numBytesDryRun' : ROAttr(),
741 'numFilesDryRun' : ROAttr(),
742 'numFilesExpected' : ROAttr(),
743 'numBytesExpected' : ROAttr(),
744 'numFilesCopied' : ROAttr(),
745 'numBytesCopied' : ROAttr(),
746 'numFilesSkipped' : ROAttr(),
747 'numBytesSkipped' : ROAttr(),
748 'numFilesDeleted' : ROAttr(),
749 'numFilesCopyFailed' : ROAttr(),
750 'numBytesCopyFailed' : ROAttr(),
751 'setupError' : ROAttr(),
752 'jobId' : ROAttr(),
753 'jobDetailsUri' : ROAttr(),
754 'dryRun' : ROAttr(),
755 'snapshottedDirs' : ROAttr(),
756 'failedFiles' : ROAttr(),
757 'runAsUser' : ROAttr(),
758 'runOnSourceAsUser' : ROAttr(),
759 'remainingTime' : ROAttr(),
760 'throughput' : ROAttr(),
761 'estimatedCompletionTime' : ROAttr(),
762 }
763
765 _ATTRIBUTES = {
766 'database' : None,
767 'tableName' : None,
768 }
769
771 return "<ApiHiveTable>: %s, %s" % (self.database, self.tableName)
772
774 _ATTRIBUTES = {
775 'database' : ROAttr(),
776 'signature' : ROAttr(),
777 }
778
780 return "<ApiImpalaUDF>: %s, %s" % (self.database, self.signature)
781
783 _ATTRIBUTES = {
784 'database' : ROAttr(),
785 'signature' : ROAttr(),
786 }
787
789 return "<ApiHiveUDF>: %s, %s" % (self.database, self.signature)
790
792 _ATTRIBUTES = {
793 'sourceService' : Attr(ApiServiceRef),
794 'tableFilters' : Attr(ApiHiveTable),
795 'exportDir' : None,
796 'force' : None,
797 'replicateData' : None,
798 'hdfsArguments' : Attr(ApiHdfsReplicationArguments),
799 'dryRun' : None,
800 'replicateImpalaMetadata' : None,
801 'runInvalidateMetadata' : None,
802 'numThreads' : None,
803 }
804
818
820 _ATTRIBUTES = {
821 'tableCount' : ROAttr(),
822 'tables' : ROAttr(ApiHiveTable),
823 'impalaUDFCount' : ROAttr(),
824 'impalaUDFs' : ROAttr(ApiImpalaUDF),
825 'hiveUDFCount' : ROAttr(),
826 'hiveUDFs' : ROAttr(ApiHiveUDF),
827 'errorCount' : ROAttr(),
828 'errors' : ROAttr(),
829 'dataReplicationResult' : ROAttr(ApiHdfsReplicationResult),
830 'dryRun' : ROAttr(),
831 'runAsUser' : ROAttr(),
832 'runOnSourceAsUser' : ROAttr(),
833 'phase' : ROAttr(),
834 'statsAvailable' : ROAttr(),
835 'dbProcessed' : ROAttr(),
836 'tableProcessed' : ROAttr(),
837 'partitionProcessed' : ROAttr(),
838 'functionProcessed' : ROAttr(),
839 'indexProcessed' : ROAttr(),
840 'statsProcessed' : ROAttr(),
841 'dbExpected' : ROAttr(),
842 'tableExpected' : ROAttr(),
843 'partitionExpected' : ROAttr(),
844 'functionExpected' : ROAttr(),
845 'indexExpected' : ROAttr(),
846 'statsExpected' : ROAttr(),
847 }
848
860
862 _ATTRIBUTES = {
863 'startTime' : Attr(datetime.datetime),
864 'endTime' : Attr(datetime.datetime),
865 'interval' : None,
866 'intervalUnit' : None,
867 'paused' : None,
868 'hdfsArguments' : Attr(ApiHdfsReplicationArguments),
869 'hiveArguments' : Attr(ApiHiveReplicationArguments),
870 'hdfsCloudArguments' : Attr(ApiHdfsCloudReplicationArguments),
871 'hiveCloudArguments' : Attr(ApiHiveCloudReplicationArguments),
872 'alertOnStart' : None,
873 'alertOnSuccess' : None,
874 'alertOnFail' : None,
875 'alertOnAbort' : None,
876 'id' : ROAttr(),
877 'nextRun' : ROAttr(datetime.datetime),
878 'history' : ROAttr(ApiReplicationCommand),
879 'active' : None
880 }
881
883 _ATTRIBUTES = {
884 'startTime' : Attr(datetime.datetime),
885 'endTime' : Attr(datetime.datetime),
886 'interval' : None,
887 'intervalUnit' : None,
888 'paused' : None,
889 'hdfsArguments' : Attr(ApiHdfsReplicationArguments),
890 'hiveArguments' : Attr(ApiHiveReplicationArguments),
891 'hdfsCloudArguments' : Attr(ApiHdfsCloudReplicationArguments),
892 'hiveCloudArguments' : Attr(ApiHiveCloudReplicationArguments),
893 'alertOnStart' : None,
894 'alertOnSuccess' : None,
895 'alertOnFail' : None,
896 'alertOnAbort' : None,
897 'id' : ROAttr(),
898 'displayName' : ROAttr(),
899 'description' : ROAttr(),
900 'nextRun' : ROAttr(datetime.datetime),
901 'history' : ROAttr(ApiReplicationCommand),
902 'active' : None,
903 'displayName' : None,
904 'description' : None
905 }
906
908 _ATTRIBUTES = {
909 'tableRegExps' : None,
910 'storage' : None,
911 }
912
917
919 _ATTRIBUTES = {
920 'snapshotName' : None,
921 'tableName' : None,
922 'creationTime' : ROAttr(datetime.datetime),
923 'storage' : None,
924 }
925
933
935 _ATTRIBUTES = {
936 'path' : None,
937 'snapshotName' : None,
938 'snapshotPath' : None,
939 'creationTime' : ROAttr(datetime.datetime),
940 }
941
949
951 _ATTRIBUTES = {
952 'processedTableCount' : ROAttr(),
953 'processedTables' : ROAttr(),
954 'unprocessedTableCount' : ROAttr(),
955 'unprocessedTables' : ROAttr(),
956 'createdSnapshotCount' : ROAttr(),
957 'createdSnapshots' : ROAttr(ApiHBaseSnapshot),
958 'deletedSnapshotCount' : ROAttr(),
959 'deletedSnapshots' : ROAttr(ApiHBaseSnapshot),
960 'creationErrorCount' : ROAttr(),
961 'creationErrors' : ROAttr(ApiHBaseSnapshotError),
962 'deletionErrorCount' : ROAttr(),
963 'deletionErrors' : ROAttr(ApiHBaseSnapshotError),
964 }
965
967 _ATTRIBUTES = {
968 'processedPathCount' : ROAttr(),
969 'processedPaths' : ROAttr(),
970 'unprocessedPathCount' : ROAttr(),
971 'unprocessedPaths' : ROAttr(),
972 'createdSnapshotCount' : ROAttr(),
973 'createdSnapshots' : ROAttr(ApiHdfsSnapshot),
974 'deletedSnapshotCount' : ROAttr(),
975 'deletedSnapshots' : ROAttr(ApiHdfsSnapshot),
976 'creationErrorCount' : ROAttr(),
977 'creationErrors' : ROAttr(ApiHdfsSnapshotError),
978 'deletionErrorCount' : ROAttr(),
979 'deletionErrors' : ROAttr(ApiHdfsSnapshotError),
980 }
981
993
995 """
996 @type name: str
997 @ivar name: Name of the snapshot policy.
998 @type description: str
999 @ivar description: Description of the snapshot policy.
1000 @type hourly_snapshots: int
1001 @ivar hourly_snapshots: Number of hourly snapshots to be retained (default: 0).
1002 @type daily_snapshots: int
1003 @ivar daily_snapshots: Number of daily snapshots to be retained (default: 0).
1004 @type weekly_snapshots: int
1005 @ivar weekly_snapshots: Number of weekly snapshots to be retained (default: 0).
1006 @type monthly_snapshots: int
1007 @ivar monthly_snapshots: Number of monthly snapshots to be retained (default: 0).
1008 @type yearly_snapshots: int
1009 @ivar yearly_snapshots: Number of yearly snapshots to be retained (default: 0).
1010 @type hours_for_hourly_snapshots: list of int
1011 @ivar hours_for_hourly_snapshots: Hours of the day that hourly snapshots should be created.
1012 Valid values are 0 to 23. If this list is empty, then hourly snapshots are
1013 created for every hour.
1014 @type minute_of_hour: int
1015 @ivar minute_of_hour: Minute in the hour that hourly, daily, weekly, monthly and yearly
1016 snapshots should be created. Valid values are 0 to 59 (default: 0).
1017 @type hour_of_day: int
1018 @ivar hour_of_day: Hour in the day that daily, weekly, monthly and yearly snapshots should be created.
1019 Valid values are 0 to 23 (default: 0).
1020 @type day_of_week: int
1021 @ivar day_of_week: Day of the week that weekly snapshots should be created.
1022 Valid values are 1 to 7, 1 representing Sunday (default: 1).
1023 @type day_of_month: int
1024 @ivar day_of_month: Day of the month that monthly and yearly snapshots should be created.
1025 Values from 1 to 31 are allowed. Additionally 0 to -30 can be used to
1026 specify offsets from the last day of the month (default: 1).
1027 @type month_of_year: int
1028 @ivar month_of_year: Month of the year that yearly snapshots should be created.
1029 Valid values are 1 to 12, 1 representing January (default: 1).
1030 @ivar alert_on_start: whether to generate alerts on start of snapshot creation/deletion activity.
1031 @ivar alert_on_success: whether to generate alerts on successful completion of snapshot creation/deletion activity.
1032 @ivar alert_on_fail: whether to generate alerts on failure of snapshot creation/deletion activity.
1033 @ivar alert_on_abort: whether to generate alerts on abort of snapshot creation/deletion activity.
1034 @ivar paused: whether to run the policy on schedule
1035 @type hbaseArguments: ApiHBaseSnapshotPolicyArguments
1036 @ivar hbaseArguments: HBase specific arguments for the replication job.
1037 @type hdfsArguments: ApiHdfsSnapshotPolicyArguments
1038 @ivar hdfsArguments: HDFS specific arguments for the replication job.
1039 """
1040 _ATTRIBUTES = {
1041 'name' : None,
1042 'description' : None,
1043 'hourlySnapshots' : None,
1044 'dailySnapshots' : None,
1045 'weeklySnapshots' : None,
1046 'monthlySnapshots' : None,
1047 'yearlySnapshots' : None,
1048 'minuteOfHour' : None,
1049 'hourOfDay' : None,
1050 'dayOfWeek' : None,
1051 'dayOfMonth' : None,
1052 'monthOfYear' : None,
1053 'hoursForHourlySnapshots' : None,
1054 'alertOnStart' : None,
1055 'alertOnSuccess' : None,
1056 'alertOnFail' : None,
1057 'alertOnAbort' : None,
1058 'paused' : None,
1059 'hbaseArguments' : Attr(ApiHBaseSnapshotPolicyArguments),
1060 'hdfsArguments' : Attr(ApiHdfsSnapshotPolicyArguments),
1061 'lastCommand' : ROAttr(ApiSnapshotCommand),
1062 'lastSuccessfulCommand' : ROAttr(ApiSnapshotCommand),
1063 }
1064
1070 """One element in a batch request."""
1071 _ATTRIBUTES = {
1072 'method' : None,
1073 'url' : None,
1074 'body' : None,
1075 'contentType' : None,
1076 'acceptType' : None,
1077 }
1078
1080 """One element in a batch response."""
1081 _ATTRIBUTES = {
1082 'statusCode' : ROAttr(),
1083 'response' : ROAttr(),
1084 }
1085
1092
1093
1094
1095
1096
1097 -class ApiConfig(BaseApiObject):
1098 _ATTRIBUTES = {
1099 'name' : None,
1100 'value' : None,
1101 'required' : ROAttr(),
1102 'default' : ROAttr(),
1103 'displayName' : ROAttr(),
1104 'description' : ROAttr(),
1105 'relatedName' : ROAttr(),
1106 'sensitive' : ROAttr(),
1107 'validationState' : ROAttr(),
1108 'validationMessage' : ROAttr(),
1109 'validationWarningsSuppressed' : ROAttr()
1110 }
1111
1112 - def __init__(self, resource_root, name=None, value=None):
1114
1116 return "<ApiConfig>: %s = %s" % (self.name, self.value)
1117
1119 _ATTRIBUTES = {
1120 'queryId' : ROAttr(),
1121 'queryState' : ROAttr(),
1122 'queryType' : ROAttr(),
1123 'statement' : ROAttr(),
1124 'database' : ROAttr(),
1125 'rowsProduced' : ROAttr(),
1126 'coordinator' : ROAttr(ApiHostRef),
1127 'user' : ROAttr(),
1128 'startTime' : ROAttr(datetime.datetime),
1129 'endTime' : ROAttr(datetime.datetime),
1130 'detailsAvailable' : ROAttr(),
1131 'attributes' : ROAttr(),
1132 'durationMillis' : ROAttr()
1133 }
1134
1136 return "<ApiImpalaQuery>: %s" % (self.queryId)
1137
1143
1144 _ATTRIBUTES = {
1145 'path' : None
1146 }
1147
1149 return "<ApiWatchedDir>: %s" % (self.path)
1150
1157
1164
1166 _ATTRIBUTES = {
1167 'details' : ROAttr()
1168 }
1169
1171 return "<AipImpalaQueryDetailsResponse> %s" % self.details
1172
1174 _ATTRIBUTES = {
1175 'warning' : ROAttr()
1176 }
1177
1179 return "<ApiImpalaCancelResponse> %s" % self.warning
1180
1182
1183 _ATTRIBUTES = {
1184 'name' : ROAttr(),
1185 'type' : ROAttr(),
1186 'displayName' : ROAttr(),
1187 'supportsHistograms' : ROAttr(),
1188 'description' : ROAttr()
1189 }
1190
1192 return "<ApiImpalaQueryAttribute> %s" % name
1193
1201
1203 _ATTRIBUTES = {
1204 'applicationId' : ROAttr(),
1205 'name' : ROAttr(),
1206 'user' : ROAttr(),
1207 'startTime' : ROAttr(datetime.datetime),
1208 'endTime' : ROAttr(datetime.datetime),
1209 'pool' : ROAttr(),
1210 'state' : ROAttr(),
1211 'progress' : ROAttr(),
1212 'mr2AppInformation' : ROAttr(ApiMr2AppInformation),
1213 'attributes' : ROAttr(),
1214 'allocatedMB' : ROAttr(),
1215 'allocatedVCores' : ROAttr(),
1216 'runningContainers' : ROAttr(),
1217 'applicationTags' : ROAttr(),
1218 'allocatedMemorySeconds' : ROAttr(),
1219 'allocatedVcoreSeconds' : ROAttr(),
1220 'containerUsedMemorySeconds' : ROAttr(),
1221 'containerUsedCpuSeconds' : ROAttr(),
1222 'containerUsedVcoreSeconds' : ROAttr(),
1223 'containerAllocatedMemorySeconds' : ROAttr(),
1224 'containerAllocatedVcoreSeconds' : ROAttr(),
1225 'containerUsedMemoryMax' : ROAttr(),
1226 }
1227
1229 return "<ApiYarnApplication>: %s" % (self.applicationId)
1230
1237
1239 _ATTRIBUTES = {
1240 'warning' : ROAttr()
1241 }
1242
1244 return "<ApiYarnKillResponse> %s" % self.warning
1245
1247
1248 _ATTRIBUTES = {
1249 'name' : ROAttr(),
1250 'type' : ROAttr(),
1251 'displayName' : ROAttr(),
1252 'supportsHistograms' : ROAttr(),
1253 'description' : ROAttr()
1254 }
1255
1257 return "<ApiYarnApplicationAttribute> %s" % name
1258
1260 _ATTRIBUTES = {
1261 'query' : None,
1262 'from' : None,
1263 'to' : None,
1264 'contentType' : None,
1265 'desiredRollup' : None,
1266 'mustUseDesiredRollup' : None
1267 }
1268
1270 return "<ApiTimeSeriesRequest>: %s" % (self.query)
1271
1273 _ATTRIBUTES = {
1274 'version' : None,
1275 'product' : None,
1276 }
1277
1279 _ATTRIBUTES = {
1280 'name' : None,
1281 'value' : None,
1282 'ref' : None,
1283 'variable' : None,
1284 'autoConfig' : None,
1285 }
1286
1295
1297 _ATTRIBUTES = {
1298 'refName' : None,
1299 'roleType' : None,
1300 }
1301
1303 _ATTRIBUTES = {
1304 'refName' : None,
1305 'cardinality' : None,
1306 'roleConfigGroupsRefNames' : None,
1307 }
1308
1310 _ATTRIBUTES = {
1311 'hostName' : None,
1312 'hostNameRange' : None,
1313 'rackId' : None,
1314 'hostTemplateRefName' : None,
1315 'roleRefNames' : None,
1316 }
1317
1319 _ATTRIBUTES = {
1320 'name' : None,
1321 'value' : None,
1322 }
1323
1325 _ATTRIBUTES = {
1326 'rcgRefName' : None,
1327 'name' : None,
1328 }
1329
1337
1347
1359
1361 """
1362 Converts a python dictionary into a list containing the proper
1363 ApiConfig encoding for configuration data.
1364
1365 @param dic: Key-value pairs to convert.
1366 @return: JSON dictionary of an ApiConfig list (*not* an ApiList).
1367 """
1368 config = [ ]
1369 for k, v in dic.iteritems():
1370 config.append({ 'name' : k, 'value': v })
1371 return { ApiList.LIST_KEY : config }
1372
1374 """
1375 Converts a python dictionary into a JSON payload.
1376
1377 The payload matches the expected "apiConfig list" type used to update
1378 configuration parameters using the API.
1379
1380 @param dic: Key-value pairs to convert.
1381 @return: String with the JSON-encoded data.
1382 """
1383 return json.dumps(config_to_api_list(dic))
1384
1386 """
1387 Converts a JSON-decoded config dictionary to a python dictionary.
1388
1389 When materializing the full view, the values in the dictionary will be
1390 instances of ApiConfig, instead of strings.
1391
1392 @param dic: JSON-decoded config dictionary.
1393 @param full: Whether to materialize the full view of the config data.
1394 @return: Python dictionary with config data.
1395 """
1396 config = { }
1397 for entry in dic['items']:
1398 k = entry['name']
1399 if full:
1400 config[k] = ApiConfig.from_json_dict(entry, None)
1401 else:
1402 config[k] = entry.get('value')
1403 return config
1404