Assign a particular instance to an existing container or to a new container
333123
private void placeFFDInstance(PackingPlanBuilder planBuilder, String componentName)
      throws ConstraintViolationException {
    if (this.numContainers == 0) {
      planBuilder.updateNumContainers(++numContainers);
    }

    try {
      planBuilder.addInstance(new ContainerIdScorer(), componentName);
    } catch (ResourceExceededException e) {
      planBuilder.updateNumContainers(++numContainers);
      planBuilder.addInstance(numContainers, componentName);
    }
  }
1326551
private void assignInstancesToContainers(PackingPlanBuilder planBuilder,
                                           Map<String, Integer> parallelismMap,
                                           PolicyType policyType)
      throws ConstraintViolationException {
    for (String componentName : parallelismMap.keySet()) {
      int numInstance = parallelismMap.get(componentName);
      for (int i = 0; i < numInstance; ++i) {
        policyType.assignInstance(planBuilder, componentName, this);
      }
    }
  }
103680
def create(self, instance):
        
        with self.flushing():
            if instance.id is None:
                instance.id = self.new_object_id()
            self.session.add(instance)
        return instance
1001539
def initChild(cls, obj, name, subContext, parent = None):
    """"""
    addr = statsId(obj)
    if addr not in cls.containerMap:
      if not parent:
        # Find out the parent of the calling object by going back through the call stack until a self != this.
        f = inspect.currentframe()
        while not cls.__getSelf(f):
          f = f.f_back
        this = cls.__getSelf(f)
        f = f.f_back
        while cls.__getSelf(f) == this or not cls.__getSelf(f):
          f = f.f_back
        parent = cls.__getSelf(f)

      # Default subcontext to an autoincrementing ID.
      if subContext is None:
        cls.subId += 1
        subContext = cls.subId

      if subContext is not '':
        path = '%s/%s' % (name, subContext)
      else:
        path = name

      # Now that we have the name, create an entry for this object.
      cls.parentMap[addr] = parent
      container = cls.getContainerForObject(statsId(parent))
      if not container and isinstance(parent, unittest.TestCase):
        cls.init(parent, '/test-case')
      cls.containerMap[addr] = cls.__getStatContainer(path, cls.getContainerForObject(statsId(parent)))
    return cls.containerMap[addr]
596551
def new(*args, &block)
      instance = allocate.tap { |obj| obj.__send__(:initialize, *args, &block) }
      IceNine.deep_freeze(instance)
    end
77871
void add(PackingPlan.InstancePlan instancePlan) {
    if (this.instances.contains(instancePlan)) {
      throw new PackingException(String.format(
          "Instance %s already exists in container %s", instancePlan, toString()));
    }
    this.instances.add(instancePlan);
  }
921598
def _post_init(self, name, container=None):
        
        self.name = name
        self.container = container
346472
def instance(self_or_cls,**params):
        

        if isinstance (self_or_cls,ParameterizedMetaclass):
            cls = self_or_cls
        else:
            p = params
            params = dict(self_or_cls.get_param_values())
            params.update(p)
            params.pop('name')
            cls = self_or_cls.__class__

        inst=Parameterized.__new__(cls)
        Parameterized.__init__(inst,**params)
        if 'name' in params:  inst.__name__ = params['name']
        else:                 inst.__name__ = self_or_cls.name
        return inst
763367
def add_service(self, cls):
        
        service_name = get_service_name(cls)
        container = self.container_cls(cls, self.config)
        self.service_map[service_name] = container
691832
def get_init_container(self,
                           init_command,
                           init_args,
                           env_vars,
                           context_mounts,
                           persistence_outputs,
                           persistence_data):
        """"""
        env_vars = to_list(env_vars, check_none=True)
        if self.original_name is not None and self.cloning_strategy == CloningStrategy.RESUME:
            return []
        if self.original_name is not None and self.cloning_strategy == CloningStrategy.COPY:
            command = InitCommands.COPY
            original_outputs_path = stores.get_experiment_outputs_path(
                persistence=persistence_outputs,
                experiment_name=self.original_name)
        else:
            command = InitCommands.CREATE
            original_outputs_path = None

        outputs_path = stores.get_experiment_outputs_path(
            persistence=persistence_outputs,
            experiment_name=self.experiment_name)
        _, outputs_volume_mount = get_pod_outputs_volume(persistence_outputs=persistence_outputs)
        volume_mounts = outputs_volume_mount + to_list(context_mounts, check_none=True)
        init_command = init_command or ["/bin/sh", "-c"]
        init_args = init_args or to_list(
            get_output_args(command=command,
                            outputs_path=outputs_path,
                            original_outputs_path=original_outputs_path))
        init_args += to_list(get_auth_context_args(entity='experiment',
                                                   entity_name=self.experiment_name))
        return [
            client.V1Container(
                name=self.init_container_name,
                image=self.init_docker_image,
                image_pull_policy=self.init_docker_image_pull_policy,
                command=init_command,
                args=[''.join(init_args)],
                env=env_vars,
                volume_mounts=volume_mounts)
        ]
703032
def container_instance_from_string(id):
    """"""
    try:
        service, instance = id.rsplit('_', 1)
        instance = int(instance)
    except (TypeError, ValueError):
        raise context.ValueError("Invalid container id %r" % id)
    return _proto.ContainerInstance(service_name=service, instance=instance)
804227
function( a, b ) {
            this.id = b.attr('id');
            this.instances = [];
            this.element = b;
            this.options = jQuery.extend(this.options, a);
            this._create();
            if ( this._init ) {
                this._init();
            }
        }
1142582
def copy(self):
        '''
        
        '''
        dup = super(Container, self).copy()
        dup._fields = [field.copy() for field in self._fields]
        dup._fields_dict = {field.get_name(): field for field in dup._fields if field.get_name() is not None}
        dup._containers = []
        for container in self._containers:
            idx = self._fields.index(container)
            dup._containers.append(dup._fields[idx])
        for field in dup._fields:
            field.enclosing = dup
        return dup
642247
def container_move(object_id, input_params={}, always_retry=False, **kwargs):
    
    return DXHTTPRequest('/%s/move' % object_id, input_params, always_retry=always_retry, **kwargs)
277746
def get_init_container(self,
                           init_command,
                           init_args,
                           env_vars,
                           context_mounts,
                           persistence_outputs,
                           persistence_data):
        """"""
        env_vars = to_list(env_vars, check_none=True)
        outputs_path = stores.get_job_outputs_path(
            persistence=persistence_outputs,
            job_name=self.job_name)
        _, outputs_volume_mount = get_pod_outputs_volume(persistence_outputs=persistence_outputs)
        volume_mounts = outputs_volume_mount + to_list(context_mounts, check_none=True)
        init_command = init_command or ["/bin/sh", "-c"]
        init_args = init_args or to_list(
            get_output_args(command=InitCommands.CREATE,
                            outputs_path=outputs_path))
        init_args += to_list(get_auth_context_args(entity='job',
                                                   entity_name=self.job_name))
        return client.V1Container(
            name=self.init_container_name,
            image=self.init_docker_image,
            image_pull_policy=self.init_docker_image_pull_policy,
            command=init_command,
            args=[''.join(init_args)],
            env=env_vars,
            volume_mounts=volume_mounts)
743430
def container_present(name, profile):
    '''
    
    '''
    containers = __salt__['libcloud_storage.list_containers'](profile)
    match = [z for z in containers if z['name'] == name]
    if match:
        return state_result(True, "Container already exists", name, {})
    else:
        result = __salt__['libcloud_storage.create_container'](name, profile)
        return state_result(True, "Created new container", name, result)
940083
def add_instance(self, name, properties):
        # type: (str, dict) -> None
        
        if name in self.__instances:
            raise NameError(name)

        # Store properties "as-is"
        self.__instances[name] = properties