Coverage Report - org.apache.giraph.comm.requests.SendAggregatorsToOwnerRequest
 
Classes in this File Line Coverage Branch Coverage Complexity
SendAggregatorsToOwnerRequest
0%
0/28
0%
0/6
2.25
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 package org.apache.giraph.comm.requests;
 20  
 
 21  
 import java.io.IOException;
 22  
 
 23  
 import org.apache.giraph.comm.GlobalCommType;
 24  
 import org.apache.giraph.comm.ServerData;
 25  
 import org.apache.giraph.comm.aggregators.AllAggregatorServerData;
 26  
 import org.apache.giraph.reducers.ReduceOperation;
 27  
 import org.apache.giraph.utils.UnsafeByteArrayInputStream;
 28  
 import org.apache.giraph.utils.UnsafeByteArrayOutputStream;
 29  
 import org.apache.giraph.utils.UnsafeReusableByteArrayInput;
 30  
 import org.apache.giraph.utils.WritableUtils;
 31  
 import org.apache.hadoop.io.LongWritable;
 32  
 import org.apache.hadoop.io.Writable;
 33  
 
 34  
 /**
 35  
  * Request to send final aggregatd values from master to worker which owns
 36  
  * the aggregators
 37  
  */
 38  
 public class SendAggregatorsToOwnerRequest
 39  
     extends ByteArrayWithSenderTaskIdRequest implements WorkerRequest {
 40  
 
 41  
   /**
 42  
    * Constructor
 43  
    *
 44  
    * @param data Serialized aggregator data
 45  
    * @param senderTaskId Sender task id
 46  
    */
 47  
   public SendAggregatorsToOwnerRequest(byte[] data, int senderTaskId) {
 48  0
     super(data, senderTaskId);
 49  0
   }
 50  
 
 51  
   /**
 52  
    * Constructor used for reflection only
 53  
    */
 54  0
   public SendAggregatorsToOwnerRequest() {
 55  0
   }
 56  
 
 57  
   @Override
 58  
   public void doRequest(ServerData serverData) {
 59  0
     UnsafeByteArrayOutputStream reusedOut = new UnsafeByteArrayOutputStream();
 60  0
     UnsafeReusableByteArrayInput reusedIn = new UnsafeReusableByteArrayInput();
 61  
 
 62  0
     UnsafeByteArrayInputStream input = getUnsafeByteArrayInput();
 63  0
     AllAggregatorServerData aggregatorData = serverData.getAllAggregatorData();
 64  
     try {
 65  0
       int num = input.readInt();
 66  0
       for (int i = 0; i < num; i++) {
 67  0
         String name = input.readUTF();
 68  0
         GlobalCommType type = GlobalCommType.values()[input.readByte()];
 69  0
         Writable value = WritableUtils.readWritableObject(input, conf);
 70  0
         if (type == GlobalCommType.SPECIAL_COUNT) {
 71  0
           aggregatorData.receivedRequestCountFromMaster(
 72  0
               ((LongWritable) value).get(),
 73  0
               getSenderTaskId());
 74  
         } else {
 75  0
           aggregatorData.receiveValueFromMaster(name, type, value);
 76  
 
 77  0
           if (type == GlobalCommType.REDUCE_OPERATIONS) {
 78  0
             ReduceOperation<Object, Writable> reduceOpCopy =
 79  
                 (ReduceOperation<Object, Writable>)
 80  0
                 WritableUtils.createCopy(reusedOut, reusedIn, value, conf);
 81  
 
 82  0
             serverData.getOwnerAggregatorData().registerReducer(
 83  
                 name, reduceOpCopy);
 84  
           }
 85  
         }
 86  
       }
 87  0
     } catch (IOException e) {
 88  0
       throw new IllegalStateException("doRequest: " +
 89  
           "IOException occurred while processing request", e);
 90  0
     }
 91  0
     aggregatorData.receivedRequestFromMaster(getData());
 92  0
   }
 93  
 
 94  
   @Override
 95  
   public RequestType getType() {
 96  0
     return RequestType.SEND_AGGREGATORS_TO_OWNER_REQUEST;
 97  
   }
 98  
 }