Beispiel #1
0
def install_block(resource_key):
  fl = file_locator.FileLocator()
  # first we need to create a new install spec
  if not fl.is_installed_resources_file_present():
      raise Exception("Something seems to be wrong with you Engage setup - expecting installed resources file at '%s' but did not find it." % fl.get_installed_resources_file())
  with open(fl.get_installed_resources_file(), "rb") as f:
      installed = json.load(f)
  block_id = resource_key["name"].replace(" ", "_")
  already_installed = False
  for res in installed:
      key = res["key"]
      if key["name"]==resource_key["name"] and \
         key["version"]==resource_key["version"]:
        already_installed = True
        break
  if already_installed:
    print "Block %s already installed" % resource_key.__repr__()
    utils.run_svcctl(fl, ["start", block_id])
  else:
    print "Installing block %s" % resource_key.__repr__()
    fl.move_installed_resources_file()
    updated = _add_resource_to_spec(block_id, resource_key, installed)
    install_spec_file = os.path.join(fl.get_config_dir(),
                                     _res_key_to_spec_file(resource_key))
    with open(install_spec_file, "wb") as f:
      json.dump(updated, f, indent=2)
    utils.run_deployer(fl, install_spec_file)
Beispiel #2
0
def start_job_and_get_nodes(node_list, config_file_name, total_nodes=None,
                            reuse_existing_installs=True):
    """Given a node list and optional number of nodes, try to get the
    requested nodes and start a job.
    """
    if not total_nodes:
        total_nodes = len(node_list)
    if total_nodes<1:
        raise DjmAdapterError("Must have at least one node")
    c = get_djm_connection()
    # make sure there aren't any dead jobs laying around
    c.cleanup_dead_coordinators()
    pool = None
    for node_name in node_list:
        n = c.find_node_by_name(node_name)
        if not n:
            raise DjmAdapterError("Node '%s' not defined" % node_name)
        if n["pool"]:
            if pool and pool!=n["pool"]:
                raise DjmAdapterError("Cannot take nodes from both pool %s and pool %s"%
                                      (pool, n["pool"]))
            pool = n["pool"]
    start_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
    j = c.start_job(config_file_name, common.JobType.ONE_TIME_JOB,
                    total_nodes, "Datablox job started %s" % start_time,
                    node_pool_name=pool, requested_nodes=node_list)
    logger.info("Started DJM job %s" % j)
    try:
        fl = FileLocator()
        allocated_nodes = c.query_nodes(job_id=j)
        djm_job = DjmJob(c, j, allocated_nodes)
        logger.info("Setting up nodes")
        # for all the non-master nodes, we setup the caretaker
        nodes_except_master = djm_job.nodes_except_master
        if len(nodes_except_master)>0:
            execute(setup_worker_node, reuse_existing_installs)
        # make sure the master node has the caretaker running
        if djm_job.has_node("master"):
            utils.run_svcctl(fl, ["start", "all"])
        return djm_job
    except KeyboardInterrupt:
        logger.exception("Got keyboard interrupt in node initialization")
        c.stop_job(j, common.JobStatus.JOB_FAILED,
                   comment="Got keyboard interrupt in node initialization")
        raise
    except Exception, e:
        logger.exception("DJM problem in node initialization: %s" % e)
        c.stop_job(j, common.JobStatus.JOB_FAILED,
                   comment="DJM problem in node initialization: %s" % e)
        raise