status.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. import logging
  17. from ambari_client.model.base_model import BaseModel
  18. from ambari_client.model import paths , utils
  19. LOG = logging.getLogger(__name__)
  20. class StatusModel(BaseModel):
  21. """
  22. The ServiceModel class
  23. """
  24. RO_ATTR = ('id',)
  25. RW_ATTR = ('status', 'requestId', "message")
  26. REF_ATTR = ('cluster_name',)
  27. def __init__(self, resource_root, status , requestId=None, message=None):
  28. #BaseModel.__init__(self, **locals())
  29. utils.retain_self_helper(BaseModel, **locals())
  30. def __str__(self):
  31. return "<<StatusModel>> status = %s ; requestId = %s ;message = %s" % (self.status, self._get_id() , self.get_message())
  32. def get_bootstrap_path(self):
  33. return paths.BOOTSTRAP_PATH + '/' + str(self.requestId)
  34. def get_request_path(self):
  35. return self.request_path
  36. def get_message(self):
  37. if hasattr(self, 'message'):
  38. return self.message
  39. else:
  40. None
  41. def is_error(self):
  42. return (self.status != 200 and self.status != 201 and self.status != 202)
  43. def _get_id(self):
  44. if hasattr(self, 'requestId') and self.requestId:
  45. return self.requestId
  46. elif hasattr(self, 'id') and self.id:
  47. return self.id
  48. else:
  49. None