/** * Get matrices metadata * @param controller * @param request * @return * @throws ServiceException */ @Override public GetMatricesResponse getMatrices(RpcController controller, GetMatricesRequest request) throws ServiceException { GetMatricesResponse.Builder builder = GetMatricesResponse.newBuilder(); AMMatrixMetaManager matrixMetaManager = context.getMatrixMetaManager(); List<String> matrixNames = request.getMatrixNamesList(); int size = matrixNames.size(); for(int i = 0; i < size; i++) { MatrixMeta matrixMeta = matrixMetaManager.getMatrix(matrixNames.get(i)); if(matrixMeta == null) { throw new ServiceException("Can not find matrix " + matrixNames.get(i)); } builder.addMatrixMetas(ProtobufUtil.convertToMatrixMetaProto(matrixMeta)); } return builder.build(); }
/** * notify a parameter server run failed * @param controller rpc controller of protobuf * @param request contains parameter server id and error message * @throws ServiceException */ @SuppressWarnings("unchecked") @Override public PSErrorResponse psError(RpcController controller, PSErrorRequest request) throws ServiceException { PSAttemptId psAttemptId = ProtobufUtil.convertToId(request.getPsAttemptId()); LOG.info("error happened in psAttempt " + psAttemptId + " error msg=" + request.getMsg()); //remove this parameter server attempt from monitor set psLastHeartbeatTS.remove(psAttemptId); context.getEventHandler().handle( new PSAttemptDiagnosticsUpdateEvent(request.getMsg(), psAttemptId)); context.getEventHandler() .handle(new PSAttemptEvent(PSAttemptEventType.PA_FAILMSG, psAttemptId)); return PSErrorResponse.newBuilder().build(); }
@Override public CreateResponseProto create(RpcController controller, CreateRequestProto req) throws ServiceException { try { HdfsFileStatus result = server.create(req.getSrc(), PBHelper.convert(req.getMasked()), req.getClientName(), PBHelper.convertCreateFlag(req.getCreateFlag()), req.getCreateParent(), (short) req.getReplication(), req.getBlockSize(), PBHelper.convertCryptoProtocolVersions( req.getCryptoProtocolVersionList())); if (result != null) { return CreateResponseProto.newBuilder().setFs(PBHelper.convert(result)) .build(); } return VOID_CREATE_RESPONSE; } catch (IOException e) { throw new ServiceException(e); } }
/** * Get locations for a partition * @param controller * @param request * @return * @throws ServiceException */ @Override public GetPartLocationResponse getPartLocation(RpcController controller, GetPartLocationRequest request) throws ServiceException { GetPartLocationResponse.Builder builder = GetPartLocationResponse.newBuilder(); List<ParameterServerId> psIds = context.getMatrixMetaManager().getPss(request.getMatrixId(), request.getPartId()); if(psIds != null) { int size = psIds.size(); for(int i = 0; i < size; i++) { Location psLocation = context.getLocationManager().getPsLocation(psIds.get(i)); if (psLocation == null) { builder.addLocations((PSLocationProto.newBuilder().setPsId( ProtobufUtil.convertToIdProto(psIds.get(i))).setPsStatus(PSStatus.PS_NOTREADY).build())); } else { builder.addLocations(ProtobufUtil.convertToPSLocProto(psIds.get(i), psLocation)); } } } return builder.build(); }
/** * response for psagent heartbeat. * * @param controller rpc controller of protobuf * @param request * @throws ServiceException */ @SuppressWarnings("unchecked") @Override public PSAgentReportResponse psAgentReport(RpcController controller, PSAgentReportRequest request) throws ServiceException { if (LOG.isDebugEnabled()) { LOG.debug("receive ps agent state report, request=" + request); } PSAgentAttemptId psAgentAttemptId = ProtobufUtil.convertToId(request.getPsAgentAttemptId()); if (!psAgentLastHeartbeatTS.containsKey(psAgentAttemptId)) { LOG.error("psagent attempt " + psAgentAttemptId + " is not in running worker attempt set now, shutdown it"); return PSAgentReportResponse.newBuilder().setCommand(PSAgentCommandProto.PSAGENT_SHUTDOWN) .build(); } else { context.getEventHandler().handle( new PSAgentAttemptStateUpdateEvent(psAgentAttemptId, request)); psAgentLastHeartbeatTS.put(psAgentAttemptId, System.currentTimeMillis()); return PSAgentReportResponse.newBuilder().setCommand(PSAgentCommandProto.PSAGENT_SUCCESS) .build(); } }
/** * psagent run falied * * @param controller rpc controller of protobuf * @param request contains psagent attempt id, error message * @throws ServiceException */ @SuppressWarnings("unchecked") @Override public PSAgentErrorResponse psAgentError(RpcController controller, PSAgentErrorRequest request) throws ServiceException { PSAgentErrorResponse.Builder resBuilder = PSAgentErrorResponse.newBuilder(); PSAgentAttemptId psAgentAttemptId = ProtobufUtil.convertToId(request.getPsAgentAttemptId()); if (!psAgentLastHeartbeatTS.containsKey(psAgentAttemptId)) { LOG.error("psagent attempt " + psAgentAttemptId + " is not in running worker attempt set now, shutdown it"); resBuilder.setCommand(PSAgentCommandProto.PSAGENT_SHUTDOWN); } else { psAgentLastHeartbeatTS.remove(psAgentAttemptId); LOG.error("error happened in psagent " + psAgentAttemptId + ", error msg:" + request.getMsg()); context.getEventHandler().handle( new PSAgentAttemptDiagnosticsUpdateEvent(psAgentAttemptId, request.getMsg())); context.getEventHandler() .handle( new PSAgentAttemptEvent(PSAgentAttemptEventType.PSAGENT_ATTEMPT_FAILMSG, psAgentAttemptId)); resBuilder.setCommand(PSAgentCommandProto.PSAGENT_SUCCESS); } return resBuilder.build(); }
/** * worker register to master * * @param controller rpc controller of protobuf * @param request contains worker attempt id, worker location * @throws ServiceException */ @SuppressWarnings("unchecked") @Override public WorkerRegisterResponse workerRegister(RpcController controller, WorkerRegisterRequest request) throws ServiceException { if (LOG.isDebugEnabled()) { LOG.debug("receive worker register, request=" + request); } WorkerRegisterResponse.Builder registerResponseBuilder = WorkerRegisterResponse.newBuilder(); WorkerAttemptId workerAttemptId = ProtobufUtil.convertToId(request.getWorkerAttemptId()); //if worker attempt id is not in monitor set, we should shutdown it if (!workerLastHeartbeatTS.containsKey(workerAttemptId)) { LOG.error("worker attempt " + workerAttemptId + " is not in running worker attempt set now, shutdown it"); registerResponseBuilder.setCommand(WorkerCommandProto.W_SHUTDOWN); } else { Location location = new Location(request.getLocation().getIp(), request.getLocation().getPort()); context.getEventHandler().handle(new WorkerAttemptRegisterEvent(workerAttemptId, location)); registerResponseBuilder.setCommand(WorkerCommandProto.W_SUCCESS); LOG.info("worker attempt " + workerAttemptId + " register finished!"); } return registerResponseBuilder.build(); }
/** * Check matrices are created successfully * @param controller rpc controller of protobuf * @param request check request that contains matrix names */ @Override public CheckMatricesCreatedResponse checkMatricesCreated(RpcController controller, CheckMatricesCreatedRequest request) throws ServiceException { List<String> names = request.getMatrixNamesList(); CheckMatricesCreatedResponse.Builder builder = CheckMatricesCreatedResponse.newBuilder(); int size = names.size(); for(int i = 0; i < size; i++) { if(!context.getMatrixMetaManager().isCreated(names.get(i))) { builder.setStatus(-1); return builder.build(); } } return builder.setStatus(0).build(); }
/** * Roll the WAL writer of the region server. * @param controller the RPC controller * @param request the request * @throws ServiceException */ @Override public RollWALWriterResponse rollWALWriter(final RpcController controller, final RollWALWriterRequest request) throws ServiceException { try { checkOpen(); requestCount.increment(); regionServer.getRegionServerCoprocessorHost().preRollWALWriterRequest(); regionServer.walRoller.requestRollAll(); regionServer.getRegionServerCoprocessorHost().postRollWALWriterRequest(); RollWALWriterResponse.Builder builder = RollWALWriterResponse.newBuilder(); return builder.build(); } catch (IOException ie) { throw new ServiceException(ie); } }
@Override public GenericRefreshResponseCollectionProto refresh( RpcController controller, GenericRefreshRequestProto request) throws ServiceException { try { List<String> argList = request.getArgsList(); String[] args = argList.toArray(new String[argList.size()]); if (!request.hasIdentifier()) { throw new ServiceException("Request must contain identifier"); } Collection<RefreshResponse> results = impl.refresh(request.getIdentifier(), args); return pack(results); } catch (IOException e) { throw new ServiceException(e); } }
@Override public AddSpanReceiverResponseProto addSpanReceiver( RpcController controller, AddSpanReceiverRequestProto req) throws ServiceException { try { SpanReceiverInfoBuilder factory = new SpanReceiverInfoBuilder(req.getClassName()); for (ConfigPair config : req.getConfigList()) { factory.addConfigurationPair(config.getKey(), config.getValue()); } long id = server.addSpanReceiver(factory.build()); return AddSpanReceiverResponseProto.newBuilder().setId(id).build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GetSnapshottableDirListingResponseProto getSnapshottableDirListing( RpcController controller, GetSnapshottableDirListingRequestProto request) throws ServiceException { try { SnapshottableDirectoryStatus[] result = server .getSnapshottableDirListing(); if (result != null) { return GetSnapshottableDirListingResponseProto.newBuilder(). setSnapshottableDirList(PBHelper.convert(result)).build(); } else { return NULL_GET_SNAPSHOTTABLE_DIR_LISTING_RESPONSE; } } catch (IOException e) { throw new ServiceException(e); } }
@Override public AppendResponseProto append(RpcController controller, AppendRequestProto req) throws ServiceException { try { EnumSetWritable<CreateFlag> flags = req.hasFlag() ? PBHelper.convertCreateFlag(req.getFlag()) : new EnumSetWritable<>(EnumSet.of(CreateFlag.APPEND)); LastBlockWithStatus result = server.append(req.getSrc(), req.getClientName(), flags); AppendResponseProto.Builder builder = AppendResponseProto.newBuilder(); if (result.getLastBlock() != null) { builder.setBlock(PBHelper.convert(result.getLastBlock())); } if (result.getFileStatus() != null) { builder.setStat(PBHelper.convert(result.getFileStatus())); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public Message callBlockingMethod(Descriptors.MethodDescriptor md, RpcController controller, Message param, Message returnType) throws ServiceException { PayloadCarryingRpcController pcrc; if (controller != null && controller instanceof PayloadCarryingRpcController) { pcrc = (PayloadCarryingRpcController) controller; if (!pcrc.hasCallTimeout()) { pcrc.setCallTimeout(channelOperationTimeout); } } else { pcrc = new PayloadCarryingRpcController(); pcrc.setCallTimeout(channelOperationTimeout); } return this.rpcClient.callBlockingMethod(md, pcrc, param, returnType, this.ticket, this.isa); }
@Override public GetProtocolVersionsResponseProto getProtocolVersions( RpcController controller, GetProtocolVersionsRequestProto request) throws ServiceException { String protocol = request.getProtocol(); GetProtocolVersionsResponseProto.Builder builder = GetProtocolVersionsResponseProto.newBuilder(); for (RPC.RpcKind r : RPC.RpcKind.values()) { long[] versions; try { versions = getProtocolVersionForRpcKind(r, protocol); } catch (ClassNotFoundException e) { throw new ServiceException(e); } ProtocolVersionProto.Builder b = ProtocolVersionProto.newBuilder(); if (versions != null) { b.setRpcKind(r.toString()); for (long v : versions) { b.addVersions(v); } } builder.addProtocolVersions(b.build()); } return builder.build(); }
@Override public GetGroupsForUserResponseProto getGroupsForUser( RpcController controller, GetGroupsForUserRequestProto request) throws ServiceException { String user = request.getUser(); try { String[] groups = real.getGroupsForUser(user); GetGroupsForUserResponseProto.Builder responseBuilder = GetGroupsForUserResponseProto.newBuilder(); for (String group : groups) { responseBuilder.addGroups(group); } return responseBuilder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public GracefulFailoverResponseProto gracefulFailover( RpcController controller, GracefulFailoverRequestProto request) throws ServiceException { try { server.gracefulFailover(); return GracefulFailoverResponseProto.getDefaultInstance(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public TestProtos.EmptyResponseProto sleep( RpcController controller, TestProtos.SleepRequestProto request) throws ServiceException { try { Thread.sleep(request.getMilliSeconds()); } catch (InterruptedException ignore) {} return TestProtos.EmptyResponseProto.newBuilder().build(); }
@Override public TestProtos.EmptyResponseProto testServerGet( RpcController controller, TestProtos.EmptyRequestProto request) throws ServiceException { if (!(Server.get() instanceof RPC.Server)) { throw new ServiceException("Server.get() failed"); } return TestProtos.EmptyResponseProto.newBuilder().build(); }
@Override public GetAclStatusResponseProto getAclStatus(RpcController controller, GetAclStatusRequestProto req) throws ServiceException { try { return PBHelper.convert(server.getAclStatus(req.getSrc())); } catch (IOException e) { throw new ServiceException(e); } }
/** * Release matrices * @param controller * @param request * @return * @throws ServiceException */ @Override public ReleaseMatricesResponse releaseMatrices(RpcController controller, ReleaseMatricesRequest request) throws ServiceException { AMMatrixMetaManager matrixMetaManager = context.getMatrixMetaManager(); List<String> matrixNames = request.getMatrixNamesList(); int size = matrixNames.size(); for(int i = 0; i < size; i++) { matrixMetaManager.releaseMatrix(matrixNames.get(i)); } return ReleaseMatricesResponse.newBuilder().build(); }
@Override public VersionResponseProto versionRequest(RpcController controller, VersionRequestProto request) throws ServiceException { NamespaceInfo info; try { info = impl.versionRequest(); } catch (IOException e) { throw new ServiceException(e); } return VersionResponseProto.newBuilder() .setInfo(PBHelper.convert(info)).build(); }
@Override public TransitionToStandbyResponseProto transitionToStandby( RpcController controller, TransitionToStandbyRequestProto request) throws ServiceException { try { server.transitionToStandby(convert(request.getReqInfo())); return TRANSITION_TO_STANDBY_RESP; } catch(IOException e) { throw new ServiceException(e); } }
@Override public SetQuotaResponse setQuota(RpcController c, SetQuotaRequest req) throws ServiceException { try { master.checkInitialized(); return master.getMasterQuotaManager().setQuota(req); } catch (Exception e) { throw new ServiceException(e); } }
@Override public void shutdown(RpcController controller, ShutdownRequest request, RpcCallback<ShutdownResponse> done) { LOG.info("Incoming " + request.getClass().getSimpleName()); ShutdownResponse response = ShutdownResponse.newBuilder() .setSenderSite(hstore_site.getSiteId()) .build(); System.exit(1); done.run(response); }
@Override public void add(RpcController controller, Value request, RpcCallback<Value> done) { counter += request.getValue(); System.out.println("add " + request.getValue() + " = " + counter); done.run(Value.newBuilder().setValue(counter).build()); }
@Override public GetTaskAttemptCompletionEventsResponseProto getTaskAttemptCompletionEvents( RpcController controller, GetTaskAttemptCompletionEventsRequestProto proto) throws ServiceException { GetTaskAttemptCompletionEventsRequest request = new GetTaskAttemptCompletionEventsRequestPBImpl(proto); try { GetTaskAttemptCompletionEventsResponse response = real.getTaskAttemptCompletionEvents(request); return ((GetTaskAttemptCompletionEventsResponsePBImpl)response).getProto(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public RollingUpgradeResponseProto rollingUpgrade(RpcController controller, RollingUpgradeRequestProto req) throws ServiceException { try { final RollingUpgradeInfo info = server.rollingUpgrade( PBHelper.convert(req.getAction())); final RollingUpgradeResponseProto.Builder b = RollingUpgradeResponseProto.newBuilder(); if (info != null) { b.setRollingUpgradeInfo(PBHelper.convert(info)); } return b.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ScanResponse scan(RpcController controller, ScanRequest request) throws ServiceException { ScanResponse.Builder builder = ScanResponse.newBuilder(); try { if (request.hasScan()) { byte[] regionName = request.getRegion().getValue().toByteArray(); builder.setScannerId(openScanner(regionName, null)); builder.setMoreResults(true); } else { long scannerId = request.getScannerId(); Result result = next(scannerId); if (result != null) { builder.addCellsPerResult(result.size()); List<CellScannable> results = new ArrayList<CellScannable>(1); results.add(result); ((PayloadCarryingRpcController) controller).setCellScanner(CellUtil .createCellScanner(results)); builder.setMoreResults(true); } else { builder.setMoreResults(false); close(scannerId); } } } catch (IOException ie) { throw new ServiceException(ie); } return builder.build(); }
@Override public GetProcedureResultResponse getProcedureResult(RpcController controller, GetProcedureResultRequest request) throws ServiceException { LOG.debug("Checking to see if procedure is done procId=" + request.getProcId()); try { master.checkInitialized(); GetProcedureResultResponse.Builder builder = GetProcedureResultResponse.newBuilder(); Pair<ProcedureInfo, Procedure> v = master.getMasterProcedureExecutor() .getResultOrProcedure(request.getProcId()); if (v.getFirst() != null) { ProcedureInfo result = v.getFirst(); builder.setState(GetProcedureResultResponse.State.FINISHED); builder.setStartTime(result.getStartTime()); builder.setLastUpdate(result.getLastUpdate()); if (result.isFailed()) { builder.setException(result.getForeignExceptionMessage()); } if (result.hasResultData()) { builder.setResult(ByteStringer.wrap(result.getResult())); } master.getMasterProcedureExecutor().removeResult(request.getProcId()); } else { Procedure proc = v.getSecond(); if (proc == null) { builder.setState(GetProcedureResultResponse.State.NOT_FOUND); } else { builder.setState(GetProcedureResultResponse.State.RUNNING); builder.setStartTime(proc.getStartTime()); builder.setLastUpdate(proc.getLastUpdate()); } } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public TruncateTableResponse truncateTable(RpcController controller, TruncateTableRequest request) throws ServiceException { try { master.truncateTable( ProtobufUtil.toTableName(request.getTableName()), request.getPreserveSplits(), request.getNonceGroup(), request.getNonce()); } catch (IOException ioe) { throw new ServiceException(ioe); } return TruncateTableResponse.newBuilder().build(); }
@Override public CancelDelegationTokenResponseProto cancelDelegationToken( RpcController controller, CancelDelegationTokenRequestProto proto) throws ServiceException { CancelDelegationTokenRequestPBImpl request = new CancelDelegationTokenRequestPBImpl(proto); try { CancelDelegationTokenResponse response = real.cancelDelegationToken(request); return ((CancelDelegationTokenResponsePBImpl)response).getProto(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public void remoteHandler(RpcController controller, TransactionFinishRequest request, RpcCallback<TransactionFinishResponse> callback) { assert(request.hasTransactionId()) : "Got " + request.getClass().getSimpleName() + " without a txn id!"; Long txn_id = Long.valueOf(request.getTransactionId()); if (debug.val) LOG.debug(String.format("Got %s for txn #%d [status=%s]", request.getClass().getSimpleName(), txn_id, request.getStatus())); // Cancel the InitCallback if it hasn't been invoked yet AbstractTransaction ts = this.hstore_site.getTransaction(txn_id); if (ts != null) { PartitionCountingCallback<AbstractTransaction> initCallback = ts.getInitCallback(); if (initCallback.isUnblocked() == false && initCallback.isAborted() == false) { initCallback.cancel(); } } this.finishPartitions.clear(); this.finishPartitions.addAll(request.getPartitionsList()); this.hstore_site.transactionFinish(txn_id, request.getStatus(), this.finishPartitions); // Send back a FinishResponse to let them know we're cool with everything... TransactionFinishResponse.Builder builder = TransactionFinishResponse.newBuilder() .setTransactionId(txn_id); for (int p : request.getPartitionsList()) { if (hstore_site.isLocalPartition(p)) builder.addPartitions(p); } // FOR if (debug.val) LOG.debug(String.format("Sending back %s for txn #%d [status=%s, partitions=%s]", TransactionFinishResponse.class.getSimpleName(), txn_id, request.getStatus(), builder.getPartitionsList())); callback.run(builder.build()); }
@Override public ShutdownResponse shutdown(RpcController controller, ShutdownRequest request) throws ServiceException { LOG.info(master.getClientIdAuditPrefix() + " shutdown"); master.shutdown(); return ShutdownResponse.newBuilder().build(); }
@Override public void remoteQueue(RpcController controller, TransactionWorkRequest request, RpcCallback<TransactionWorkResponse> callback) { if (debug.val) LOG.debug(String.format("Executing %s using remote handler for txn #%d", request.getClass().getSimpleName(), request.getTransactionId())); this.remoteHandler(controller, request, callback); }
/** * Start executing. * @param controller rpc controller of protobuf * @param request start request * @throws ServiceException */ @Override public StartResponse start(RpcController controller, StartRequest request) throws ServiceException { LOG.info("start to calculation"); context.getApp().startExecute(); return StartResponse.newBuilder().build(); }
@Override public ModifyTableResponse modifyTable(RpcController controller, ModifyTableRequest req) throws ServiceException { try { master.modifyTable( ProtobufUtil.toTableName(req.getTableName()), HTableDescriptor.convert(req.getTableSchema()), req.getNonceGroup(), req.getNonce()); } catch (IOException ioe) { throw new ServiceException(ioe); } return ModifyTableResponse.newBuilder().build(); }
@Override public ListCorruptFileBlocksResponseProto listCorruptFileBlocks( RpcController controller, ListCorruptFileBlocksRequestProto req) throws ServiceException { try { CorruptFileBlocks result = server.listCorruptFileBlocks( req.getPath(), req.hasCookie() ? req.getCookie(): null); return ListCorruptFileBlocksResponseProto.newBuilder() .setCorrupt(PBHelper.convert(result)) .build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public CreateTableResponse createTable(RpcController controller, CreateTableRequest req) throws ServiceException { HTableDescriptor hTableDescriptor = HTableDescriptor.convert(req.getTableSchema()); byte [][] splitKeys = ProtobufUtil.getSplitKeysArray(req); try { long procId = master.createTable(hTableDescriptor, splitKeys, req.getNonceGroup(), req.getNonce()); return CreateTableResponse.newBuilder().setProcId(procId).build(); } catch (IOException ioe) { throw new ServiceException(ioe); } }
public GetThreadStackResponse workerThreadStack(RpcController controller, GetThreadStackRequest request) throws ServiceException { String stackTraceInfoString = getThreadStack(); GetThreadStackResponse getThreadStackResponse = GetThreadStackResponse.newBuilder().setStack(stackTraceInfoString).build(); return getThreadStackResponse; }