Writes all submissions to datastore.
12643
def _write_to_datastore(self):
    """"""
    # Populate datastore
    roots_and_submissions = zip([ATTACKS_ENTITY_KEY,
                                 TARGET_ATTACKS_ENTITY_KEY,
                                 DEFENSES_ENTITY_KEY],
                                [self._attacks,
                                 self._targeted_attacks,
                                 self._defenses])
    client = self._datastore_client
    with client.no_transact_batch() as batch:
      for root_key, submissions in roots_and_submissions:
        batch.put(client.entity(client.key(*root_key)))
        for k, v in iteritems(submissions):
          entity = client.entity(client.key(
              *(root_key + [KIND_SUBMISSION, k])))
          entity['submission_path'] = v.path
          entity.update(participant_from_submission_path(v.path))
          batch.put(entity)
1080513
public void write(DataOutput out) throws IOException {
    out.writeBoolean(corrupt);
    out.writeLong(offset);
    b.write(out);
    out.writeInt(locs.length);
    for (int i = 0; i < locs.length; i++) {
      locs[i].write(out);
    }
  }
120333
def write_single_batch_images_to_datastore(self, batch_id):
    """"""
    client = self._datastore_client
    with client.no_transact_batch() as client_batch:
      self._write_single_batch_images_internal(batch_id, client_batch)
950134
def write_remaining(self):
        
        if not self.results:
            return
        with db.execution_context():
            with db.atomic():
                Result.insert_many(self.results).execute()
        del self.results[:]
1090385
public void dumpAll(FormattedWriter fw)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "dumpAll");

        try
        {
            xmlRequestWriteOnFile(fw);
            xmlWriteRawOn(fw, true);
            fw.flush();
        } catch (IOException e)
        {
            // No FFDC Code Needed
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                SibTr.event(this, tc, "Exception caught writing Mmessage store dump!", e);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "dumpAll");
    }
479868
def write(self):
        """"""
        if (self.data):
            dataPath = self.client.local_dir / (urllib.parse.quote_plus(self.uri)+'.json')
            with dataPath.open(mode='w') as dump_file:
                json.dump(self.data, dump_file)
                dump_file.close()
            logger.info('Wrote ' + self.uri + ' to file')
            return True
        else:
            logger.warning('No data to write for ' + self.uri)
            return False
758834
function () {
    var self = this;
    if (!self._waitingForQuiescence())
      self._flushBufferedWrites();
    _.each(self._stores, function (s) {
      s.saveOriginals();
    });
  }
1292528
public static void updateAll(DataStore dataStore, Iterable<Update> updates, Set<String> tags) {
        updateAll(dataStore, updates.iterator(), tags);
    }
54037
protected function submitEditStore()
    {
        if ($this->isPosted('delete')) {
            $this->deleteStore();
        } else if ($this->isPosted('save') && $this->validateEditStore()) {
            if (isset($this->data_store['store_id'])) {
                $this->updateStore();
            } else {
                $this->addStore();
            }
        }
    }
770744
@Override
    public void write(Iterable<QueryResult> results) {

        List<QueryResult> jvm_os_counters = new ArrayList<QueryResult>();
        List<QueryResult> jvm_gc_counters = new ArrayList<QueryResult>();
        List<QueryResult> jvm_runtime_counters = new ArrayList<QueryResult>();
        List<QueryResult> jvm_class_counters = new ArrayList<QueryResult>();
        List<QueryResult> jvm_thread_counters = new ArrayList<QueryResult>();
        List<QueryResult> heap_counters = new ArrayList<QueryResult>();
        List<QueryResult> nonheap_counters = new ArrayList<QueryResult>();
        List<QueryResult> tomcat_thread_pool_counters = new ArrayList<QueryResult>();
        List<QueryResult> tomcat_grp_counters = new ArrayList<QueryResult>();
        List<QueryResult> tomcat_manager_counters = new ArrayList<QueryResult>();
        List<QueryResult> tomcat_servlet_counters = new ArrayList<QueryResult>();
        List<QueryResult> tomcat_db_counters = new ArrayList<QueryResult>();
        List<QueryResult> jmxtrans_counters = new ArrayList<QueryResult>();
        List<QueryResult> app_counters = new ArrayList<QueryResult>();
        List<QueryResult> app_sales_counters = new ArrayList<QueryResult>();

        long epochInMillis = 0;
        String myname =  null;
        Object myval = null;
        long thisPID = 0;
        String tmp = null;
        String pidHost = null;

        String delims = "[.]";
        for (QueryResult result : results) {
            epochInMillis = result.getEpochInMillis();
            myname =  result.getName();
            myval = result.getValue();
            String valstr = myval.toString();
            thisPID = getPID();
            tmp = String.valueOf(thisPID);
            pidHost = source + "." + tmp;

            String[] parts = myname.split(delims);
            if( parts.length > 0 ) {
                String p1 = parts[0];
                if( (jmxtrans_metric_groupID != null) && (p1.equals("jmxtrans")) )  {
                    QueryResult new_result = new QueryResult(myname, pidHost, myval, epochInMillis);
                    jmxtrans_counters.add(new_result);
                } else if( p1.equals("jvm") ) {
                    if( parts[1].equals("os")) {
                        if (parts[2].equals("OpenFileDescriptorCount")) {
                            QueryResult new_result = new QueryResult(myname, pidHost, myval, epochInMillis);
                            jvm_os_counters.add(new_result);
                        } else if (parts[2].equals("CommittedVirtualMemorySize")){
                            float fval = Float.parseFloat(valstr);
                            try {
                                fval = fval/(1024.0f*1024.0f);  
                            } catch (Exception e) {
                                exceptionCounter.incrementAndGet();
                                logger.info("Exception doing Float: ", e);
                            }
                            QueryResult new_result = new QueryResult(myname, pidHost, fval, epochInMillis);
                            jvm_os_counters.add(new_result);
                        } else if (parts[2].equals("ProcessCpuTime")) { 
                            float fval = Float.parseFloat(valstr);
                            try {
                                fval = fval/(1000.0f*1000.0f*1000.0f);  
                            } catch (Exception e) {
                                exceptionCounter.incrementAndGet();
                                logger.warn("Exception doing Float: ", e);
                            }
                            QueryResult new_result = new QueryResult(myname, pidHost, fval, epochInMillis);
                            jvm_os_counters.add(new_result);
                        }
                    } else if( (parts[1].equals("runtime")) && (parts[2].equals("Uptime")) ) { 
                        float fval = Float.parseFloat(valstr);
                        try {
                            fval = fval/(1000.0f*60.0f);  
                        } catch (Exception e) {
                            exceptionCounter.incrementAndGet();
                            logger.warn("Exception doing Float: ", e);
                        }
                        QueryResult new_result = new QueryResult(myname, pidHost, fval, epochInMillis);
                        jvm_runtime_counters.add(new_result); 
                    } else if( (parts[1].equals("loadedClasses")) && (parts[2].equals("LoadedClassCount")) ) {
                        // jvm.loadedClasses.LoadedClassCount 5099 1374549969
                        QueryResult new_result = new QueryResult(myname, pidHost, myval, epochInMillis);
                        jvm_class_counters.add(new_result); 
                    } else if( (parts[1].equals("thread")) && (parts[2].equals("ThreadCount")) ){
                        // jvm.thread.ThreadCount 13 1374549940
                        QueryResult new_result = new QueryResult(myname, pidHost, myval, epochInMillis);
                        jvm_thread_counters.add(new_result);
                    } else if( (parts[1].equals("gc")) &&
                        ( (parts[2].equals("Copy")) ||  (parts[2].equals("MarkSweepCompact")) ) &&
                        ( (parts[3].equals("CollectionCount")) ||  (parts[3].equals("CollectionTime")) ) ) {
                        // jvm.gc.Copy.CollectionCount 68 1374549940
                        QueryResult new_result = new QueryResult(myname, pidHost, myval, epochInMillis);
                        jvm_gc_counters.add(new_result);
                    } else if( parts[1].equals("memorypool") ){ 
                        if( ( (parts[2].equals("Perm_Gen")) || (parts[2].equals("Code_Cache")) ) && 
                            ( (parts[4].equals("committed")) || (parts[4].equals("used"))  ) ) {     
                            myname = "jvmNonHeapMemoryUsage";
                            String fullID = pidHost + "." + parts[2] + "." + parts[4];
                            float fval = Float.parseFloat(valstr);
                            try {
                                fval = fval/(1024.0f*1024.0f);
                            } catch (Exception e) {
                                exceptionCounter.incrementAndGet();
                                logger.warn("Exception doing Float: ", e);
                            }
                            QueryResult new_result = new QueryResult(myname, fullID, fval, epochInMillis);
                            nonheap_counters.add(new_result);
                        } else if( ( (parts[2].equals("Eden_Space")) || 
                                     (parts[2].equals("Survivor_Space")) || 
                                     (parts[2].equals("Tenured_Gen")) 
                                    ) && (  (parts[4].equals("committed")) ||  (parts[4].equals("used"))  ) ) {    
                            myname = "jvmHeapMemoryUsage";
                            String fullID = pidHost + "." + parts[2] + "." + parts[4];
                            float fval = Float.parseFloat(valstr);
                            try {
                                fval = fval/(1024.0f*1024.0f);
                            } catch (Exception e) {
                                exceptionCounter.incrementAndGet();
                                logger.warn("Exception doingFloat: ", e);
                            }
                            QueryResult new_result = new QueryResult(myname, fullID, fval, epochInMillis);
                            heap_counters.add(new_result);
                        }
                    } 
                } else if( p1.equals("tomcat") ) {
                    if( (parts[1].equals("thread-pool")) &&  
                         ( (parts[3].equals("currentThreadsBusy")) || (parts[3].equals("currentThreadCount")) ) ){
                        // tomcat.thread_pool.http-bio-8080.currentThreadCount 0 1374549955
                        String connector = parts[2];
                        myname = parts[0] + "." + parts[1] + "." + parts[3];
                        String fullID = pidHost + "." + connector;
                        QueryResult new_result = new QueryResult(myname, fullID, myval, epochInMillis);
                        tomcat_thread_pool_counters.add(new_result);
                   } else if( parts[1].equals("global-request-processor") ) {
                        // tomcat.global-request-processor.http-bio-8080.bytesSent
                        String connector = parts[2];
                        myname = parts[0] + "." + parts[1] + "." + parts[3];
                        String fullID = pidHost + "." + connector;
                        if( parts[3].equals("processingTime")) {
                            float fval = Float.parseFloat(valstr);
                            try {
                                fval = fval/(1024.0f);
                            } catch (Exception e) {
                                exceptionCounter.incrementAndGet();
                                logger.warn("Exception doingFloat: ", e);
                            }
                            QueryResult new_result = new QueryResult(myname, fullID, fval, epochInMillis);
                            tomcat_grp_counters.add(new_result);
                        } else {
                            QueryResult new_result = new QueryResult(myname, fullID, myval, epochInMillis);
                            tomcat_grp_counters.add(new_result);
                        }
                    } else if( (parts[1].equals("manager"))  && (parts[4].equals("activeSessions")) ){
                        //  tomcat.manager.localhost._docs.activeSessions 0 1374549955
                        String myhost = parts[2];
                        String mycontext = parts[3];
                        myname = parts[0] + "." + parts[1] + "." + parts[4];
                        String fullID = pidHost + "." + myhost + "." + mycontext;
                        QueryResult new_result = new QueryResult(myname, fullID, myval, epochInMillis);
                        tomcat_manager_counters.add(new_result);
                    } else if( (parts[1].equals("servlet")) && 
                          ( (parts[4].equals("processingTime")) || 
                            (parts[4].equals("errorCount")) || 
                            (parts[4].equals("requestCount")) ) ){
                        // tomcat.servlet.__localhost_cocktail-app-1_0_9-SNAPSHOT.spring-mvc.processingTime
                        String myWebmodule = parts[2];
                        String myServletname = parts[3];
                        myname = parts[0] + "." + parts[1] + "." + parts[4];
                        String fullID = pidHost + "." + myWebmodule + "." + myServletname;
                        QueryResult new_result = new QueryResult(myname, fullID, myval, epochInMillis);
                        tomcat_servlet_counters.add(new_result);
                    } else if( (tomcat_db_groupID != null) && (parts[1].equals("data-source")) ) {                   
                        String myhost = parts[2];
                        String mycontext = parts[3];
                        String mydbname = parts[4];
                        myname = parts[0] + "." + parts[1] + "." + parts[5];
                        String fullID = pidHost + "." + myhost + "." + mycontext + "." + mydbname;
                        QueryResult new_result = new QueryResult(myname, fullID, myval, epochInMillis);
                        tomcat_db_counters.add(new_result);
                    }
                } else if( (app_groupID != null) && (p1.equals("cocktail")) ) {
                    if( !(parts[1].equals("CreatedCocktailCount")) &&  !(parts[1].equals("UpdatedCocktailCount")) ) {
                        QueryResult new_result = new QueryResult(myname, pidHost, myval, epochInMillis);
                        app_counters.add(new_result);
                    }
                } else if( ( (app_sales_groupID != null) && (p1.equals("sales")) ) &&
                      ( (parts[1].equals("ordersCounter")) || 
                        (parts[1].equals("itemsCounter")) || 
                        (parts[1].equals("revenueInCentsCounter")) ) ){
                        QueryResult new_result = new QueryResult(myname, pidHost, myval, epochInMillis);
                        app_sales_counters.add(new_result);
                }
            } else {
                logger.warn("parts return NULL!!!");
            }
        }
        if(!jvm_os_counters.isEmpty()) {
            sort_n_send(jvm_os_groupID, jvm_os_counters);
        }
        if(!jvm_gc_counters.isEmpty()) {
            sort_n_send(jvm_gc_groupID, jvm_gc_counters);
        }
        if(!jvm_runtime_counters.isEmpty()) {
            sort_n_send(jvm_runtime_groupID, jvm_runtime_counters);
        }
        if(!jvm_class_counters.isEmpty()) {
            sort_n_send(jvm_class_groupID, jvm_class_counters);
        }
        if(!jvm_thread_counters.isEmpty()) {
            sort_n_send(jvm_thread_groupID, jvm_thread_counters);
        }
        if(!heap_counters.isEmpty()) {
            sort_n_send(heap_metric_groupID, heap_counters);
        }
        if(!nonheap_counters.isEmpty()) {
            sort_n_send(nonheap_metric_groupID, nonheap_counters);
        }
        if(!tomcat_thread_pool_counters.isEmpty()) {
            sort_n_send(tomcat_thread_pool_groupID, tomcat_thread_pool_counters);
        }
        if(!tomcat_grp_counters.isEmpty()) {
            sort_n_send(tomcat_grp_groupID,tomcat_grp_counters);
        }
        if(!tomcat_servlet_counters.isEmpty()) {
            sort_n_send(tomcat_servlet_groupID, tomcat_servlet_counters);
        }
        if(!tomcat_manager_counters.isEmpty()) {
            sort_n_send(tomcat_manager_groupID, tomcat_manager_counters);
        }
        if(!tomcat_db_counters.isEmpty()) {
            sort_n_send(tomcat_db_groupID, tomcat_db_counters);
        }
        if(!jmxtrans_counters.isEmpty()) {
            sort_n_send(jmxtrans_metric_groupID, jmxtrans_counters);
        }
        if(!app_counters.isEmpty()) {
            sort_n_send(app_groupID, app_counters);
        }
        if(!app_sales_counters.isEmpty()) {
            sort_n_send(app_sales_groupID, app_sales_counters);
        }
    }
472047
def WriteFlowLogEntries(self, entries):
    """"""
    flow_ids = [(e.client_id, e.flow_id) for e in entries]
    for f in flow_ids:
      if f not in self.flows:
        raise db.AtLeastOneUnknownFlowError(flow_ids)

    for e in entries:
      dest = self.flow_log_entries.setdefault((e.client_id, e.flow_id), [])
      to_write = e.Copy()
      to_write.timestamp = rdfvalue.RDFDatetime.Now()
      dest.append(to_write)
790934
def write_all(key, data = nil, parameters = {}, conditions = {})
      @stores.map {|s| s.write_all(key, data, parameters, conditions)}.all?
    end
1000306
public void dumpAll(Iterator<? extends YamlNode> data, Writer output) {
        getDelegate().dumpAll(data, output);
    }
171806
public static void write(IDataSet dataSet, Writer writer) throws DataSetException {
		logger.debug("write(dataSet={}, writer={}) - start", dataSet, writer);
		write(dataSet, writer, null);
	}
144718
def fill_out_and_submit(self, data, prefix='', skip_reset=False):
        
        self.fill_out(data, prefix, skip_reset)
        self.submit()
893905
def init_from_adversarial_batches_write_to_datastore(self, submissions,
                                                       adv_batches):
    
    # prepare classification batches
    idx = 0
    for s_id in iterkeys(submissions.defenses):
      for adv_id in iterkeys(adv_batches.data):
        class_batch_id = CLASSIFICATION_BATCH_ID_PATTERN.format(idx)
        idx += 1
        self.data[class_batch_id] = {
            'adversarial_batch_id': adv_id,
            'submission_id': s_id,
            'result_path': os.path.join(
                self._round_name,
                CLASSIFICATION_BATCHES_SUBDIR,
                s_id + '_' + adv_id + '.csv')
        }
    # save them to datastore
    client = self._datastore_client
    with client.no_transact_batch() as batch:
      for key, value in iteritems(self.data):
        entity = client.entity(client.key(KIND_CLASSIFICATION_BATCH, key))
        entity.update(value)
        batch.put(entity)
423353
def bulk_submit(cls, imports, api=None):
        
        if not imports:
            raise SbgError('Imports are required')

        api = api or cls._API

        items = []
        for import_ in imports:
            volume = Transform.to_volume(import_.get('volume'))
            location = Transform.to_location(import_.get('location'))
            project = Transform.to_project(import_.get('project'))
            name = import_.get('name', None)
            overwrite = import_.get('overwrite', False)

            item = {
                'source': {
                    'volume': volume,
                    'location': location
                },
                'destination': {
                    'project': project
                },
                'overwrite': overwrite
            }

            if name:
                item['destination']['name'] = name

            items.append(item)

        data = {'items': items}

        response = api.post(url=cls._URL['bulk_create'], data=data)
        return ImportBulkRecord.parse_records(response=response, api=api)