コード例 #1
0
def process_stack_definition_artifact(artifact, artifact_source_dir, options):
    """
  Process stack-definition artifact
  :param artifact: Artifact metadata
  :param artifact_source_dir: Location of artifact in the management pack
  :param options: Command line options
  """
    # Get ambari mpack properties
    stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties(
    )
    stack_name = None
    if "stack_name" in artifact:
        stack_name = artifact.stack_name
    if not stack_name:
        print_error_msg(
            "Must provide stack name for stack-definition artifact!")
        raise FatalException(
            -1, 'Must provide stack name for stack-definition artifact!')
    stack_version = None
    if "stack_version" in artifact:
        stack_version = artifact.stack_version
    if not stack_version:
        print_error_msg(
            "Must provide stack version for stack-definition artifact!")
        raise FatalException(
            -1, 'Must provide stack version for stack-definition artifact!')
    dest_link = os.path.join(stack_location, stack_name, stack_version)
    if options.force and os.path.islink(dest_link):
        sudo.unlink(dest_link)
    sudo.symlink(artifact_source_dir, dest_link)
コード例 #2
0
ファイル: system.py プロジェクト: mx739150/ambari-app
    def action_create(self):
        path = self.resource.path

        if sudo.path_lexists(path):
            oldpath = os.path.realpath(path)
            if oldpath == self.resource.to:
                return
            if not sudo.path_lexists(path):
                raise Fail(
                    "%s trying to create a symlink with the same name as an existing file or directory"
                    % self.resource)
            Logger.info("%s replacing old symlink to %s" %
                        (self.resource, oldpath))
            sudo.unlink(path)

        if self.resource.hard:
            if not sudo.path_exists(self.resource.to):
                raise Fail(
                    "Failed to apply %s, linking to nonexistent location %s" %
                    (self.resource, self.resource.to))
            if sudo.path_isdir(self.resource.to):
                raise Fail(
                    "Failed to apply %s, cannot create hard link to a directory (%s)"
                    % (self.resource, self.resource.to))

            Logger.info("Creating hard %s" % self.resource)
            sudo.link(self.resource.to, path)
        else:
            if not sudo.path_exists(self.resource.to):
                Logger.info("Warning: linking to nonexistent location %s" %
                            self.resource.to)

            Logger.info("Creating symbolic %s to %s" %
                        (self.resource, self.resource.to))
            sudo.symlink(self.resource.to, path)
コード例 #3
0
def process_stack_extension_definition_artifact(artifact, artifact_source_dir, options):
  """
  Process stack-extension-definition artifact
  :param artifact: Artifact metadata
  :param artifact_source_dir: Location of artifact in the management pack
  :param options: Command line options
  """
  # Get ambari mpack properties
  stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
  service_name = None
  if "service_name" in artifact:
    service_name = artifact.service_name
  if not service_name:
    print_error_msg("Must provide service name for stack-extension-definition artifact!")
    raise FatalException(-1, 'Must provide service name for stack-extension-definition artifact!')
  applicable_stacks = None
  if "applicable_stacks" in artifact:
    applicable_stacks = artifact.applicable_stacks
  if not applicable_stacks:
    print_error_msg("Must provide applicable stacks for stack-extension-definition artifact!")
    raise FatalException(-1, 'Must provide applicable stacks for stack-extension-definition artifact!')
  for applicable_stack in applicable_stacks:
    stack_name = applicable_stack.stack_name
    stack_version = applicable_stack.stack_version
    dest_stack_path = os.path.join(stack_location, stack_name)
    dest_stack_version_path = os.path.join(dest_stack_path, stack_version)
    dest_stack_services_path = os.path.join(dest_stack_version_path, "services")
    dest_link = os.path.join(dest_stack_services_path, service_name)
    if os.path.exists(dest_stack_path) and os.path.exists(dest_stack_version_path):
      if not os.path.exists(dest_stack_services_path):
        sudo.makedir(dest_stack_services_path, 0755)
      if options.force and os.path.islink(dest_link):
        sudo.unlink(dest_link)
      sudo.symlink(artifact_source_dir, dest_link)
コード例 #4
0
ファイル: system.py プロジェクト: maduhu/HDP2.5-ambari
  def action_create(self):
    path = self.resource.path

    if sudo.path_lexists(path):
      oldpath = os.path.realpath(path)
      if oldpath == self.resource.to:
        return
      if not sudo.path_lexists(path):
        raise Fail(
          "%s trying to create a symlink with the same name as an existing file or directory" % self.resource)
      Logger.info("%s replacing old symlink to %s" % (self.resource, oldpath))
      sudo.unlink(path)
      
    if self.resource.hard:
      if not sudo.path_exists(self.resource.to):
        raise Fail("Failed to apply %s, linking to nonexistent location %s" % (self.resource, self.resource.to))
      if sudo.path_isdir(self.resource.to):
        raise Fail("Failed to apply %s, cannot create hard link to a directory (%s)" % (self.resource, self.resource.to))
      
      Logger.info("Creating hard %s" % self.resource)
      sudo.link(self.resource.to, path)
    else:
      if not sudo.path_exists(self.resource.to):
        Logger.info("Warning: linking to nonexistent location %s" % self.resource.to)
        
      Logger.info("Creating symbolic %s to %s" % (self.resource, self.resource.to))
      sudo.symlink(self.resource.to, path)
コード例 #5
0
def create_symlink_using_path(src_path, dest_link, force=False):
    """
  Helper function to create symbolic link (dest_link -> src_path)
  :param src_path: Source path
  :param dest_link: Destination link
  :param force: Remove existing symlink
  """
    if force and os.path.islink(dest_link):
        sudo.unlink(dest_link)
    sudo.symlink(src_path, dest_link)
    print_info_msg("Symlink: " + dest_link)
コード例 #6
0
def create_symlink(src_dir, dest_dir, file_name, force=False):
    """
  Helper function to create symbolic link (dest_dir/file_name -> src_dir/file_name)
  :param src_dir: Source directory
  :param dest_dir: Destination directory
  :param file_name: File name
  :param force: Remove existing symlink
  """
    src_path = os.path.join(src_dir, file_name)
    dest_link = os.path.join(dest_dir, file_name)
    if force and os.path.islink(dest_link):
        sudo.unlink(dest_link)
    sudo.symlink(src_path, dest_link)
コード例 #7
0
def process_stack_addon_service_definitions_artifact(artifact,
                                                     artifact_source_dir,
                                                     options):
    """
  Process stack addon service definitions artifact
  :param artifact: Artifact metadata
  :param artifact_source_dir: Location of artifact in the management pack
  :param options: Command line options
  """
    # Get ambari mpack properties
    stack_location, extension_location, service_definitions_location, mpacks_staging_location, dashboard_location = get_mpack_properties(
    )
    service_versions_map = None
    if "service_versions_map" in artifact:
        service_versions_map = artifact.service_versions_map
    if not service_versions_map:
        msg = "Must provide service versions map for " + STACK_ADDON_SERVICE_DEFINITIONS_ARTIFACT_NAME + " artifact!"
        print_error_msg(msg)
        raise FatalException(-1, msg)
    for service_name in sorted(os.listdir(artifact_source_dir)):
        source_service_path = os.path.join(artifact_source_dir, service_name)
        for service_version in sorted(os.listdir(source_service_path)):
            source_service_version_path = os.path.join(source_service_path,
                                                       service_version)
            for service_version_entry in service_versions_map:
                if service_name == service_version_entry.service_name and service_version == service_version_entry.service_version:
                    applicable_stacks = service_version_entry.applicable_stacks
                    for applicable_stack in applicable_stacks:
                        stack_name = applicable_stack.stack_name
                        stack_version = applicable_stack.stack_version
                        dest_stack_path = os.path.join(stack_location,
                                                       stack_name)
                        dest_stack_version_path = os.path.join(
                            dest_stack_path, stack_version)
                        dest_stack_services_path = os.path.join(
                            dest_stack_version_path, SERVICES_DIRNAME)
                        dest_link = os.path.join(dest_stack_services_path,
                                                 service_name)
                        if os.path.exists(dest_stack_path) and os.path.exists(
                                dest_stack_version_path):
                            if not os.path.exists(dest_stack_services_path):
                                sudo.makedir(dest_stack_services_path, 0755)
                            if options.force and os.path.islink(dest_link):
                                sudo.unlink(dest_link)
                            sudo.symlink(source_service_version_path,
                                         dest_link)
                            create_dashboard_symlinks(
                                source_service_version_path, service_name,
                                dashboard_location, options)