org.apache.hadoop.yarn.api.records.impl.pb.ProtoUtils Java Examples

The following examples show how to use org.apache.hadoop.yarn.api.records.impl.pb.ProtoUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetClusterNodesRequestPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void initNodeStates() {
  if (this.states != null) {
    return;
  }
  GetClusterNodesRequestProtoOrBuilder p = viaProto ? proto : builder;
  List<NodeStateProto> list = p.getNodeStatesList();
  this.states = EnumSet.noneOf(NodeState.class);

  for (NodeStateProto c : list) {
    this.states.add(ProtoUtils.convertFromProtoFormat(c));
  }
}
 
Example #2
Source File: GetApplicationsRequestPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void initApplicationStates() {
  if (this.applicationStates != null) {
    return;
  }
  GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder;
  List<YarnApplicationStateProto> appStatesList =
      p.getApplicationStatesList();
  this.applicationStates = EnumSet.noneOf(YarnApplicationState.class);

  for (YarnApplicationStateProto c : appStatesList) {
    this.applicationStates.add(ProtoUtils.convertFromProtoFormat(c));
  }
}
 
Example #3
Source File: GetApplicationsRequestPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void initScope() {
  if (this.scope != null) {
    return;
  }
  GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder;
  this.scope = ProtoUtils.convertFromProtoFormat(p.getScope());
}
 
Example #4
Source File: AllocateResponsePBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void setAMCommand(AMCommand command) {
  maybeInitBuilder();
  if (command == null) {
    builder.clearAMCommand();
    return;
  }
  builder.setAMCommand(ProtoUtils.convertToProtoFormat(command));
}
 
Example #5
Source File: GetClusterNodesRequestPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void initNodeStates() {
  if (this.states != null) {
    return;
  }
  GetClusterNodesRequestProtoOrBuilder p = viaProto ? proto : builder;
  List<NodeStateProto> list = p.getNodeStatesList();
  this.states = EnumSet.noneOf(NodeState.class);

  for (NodeStateProto c : list) {
    this.states.add(ProtoUtils.convertFromProtoFormat(c));
  }
}
 
Example #6
Source File: GetClusterNodesRequestPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void mergeLocalToBuilder() {
  if (this.states != null) {
    maybeInitBuilder();
    builder.clearNodeStates();
    Iterable<NodeStateProto> iterable = new Iterable<NodeStateProto>() {
      @Override
      public Iterator<NodeStateProto> iterator() {
        return new Iterator<NodeStateProto>() {

          Iterator<NodeState> iter = states.iterator();

          @Override
          public boolean hasNext() {
            return iter.hasNext();
          }

          @Override
          public NodeStateProto next() {
            return ProtoUtils.convertToProtoFormat(iter.next());
          }

          @Override
          public void remove() {
            throw new UnsupportedOperationException();

          }
        };

      }
    };
    builder.addAllNodeStates(iterable);
  }
}
 
Example #7
Source File: RegisterApplicationMasterResponsePBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void addApplicationACLs() {
  maybeInitBuilder();
  builder.clearApplicationACLs();
  if (applicationACLS == null) {
    return;
  }
  Iterable<? extends ApplicationACLMapProto> values
      = new Iterable<ApplicationACLMapProto>() {

    @Override
    public Iterator<ApplicationACLMapProto> iterator() {
      return new Iterator<ApplicationACLMapProto>() {
        Iterator<ApplicationAccessType> aclsIterator = applicationACLS
            .keySet().iterator();

        @Override
        public boolean hasNext() {
          return aclsIterator.hasNext();
        }

        @Override
        public ApplicationACLMapProto next() {
          ApplicationAccessType key = aclsIterator.next();
          return ApplicationACLMapProto.newBuilder().setAcl(
              applicationACLS.get(key)).setAccessType(
              ProtoUtils.convertToProtoFormat(key)).build();
        }

        @Override
        public void remove() {
          throw new UnsupportedOperationException();
        }
      };
    }
  };
  this.builder.addAllApplicationACLs(values);
}
 
Example #8
Source File: RegisterApplicationMasterResponsePBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void initApplicationACLs() {
  if (this.applicationACLS != null) {
    return;
  }
  RegisterApplicationMasterResponseProtoOrBuilder p = viaProto ? proto
      : builder;
  List<ApplicationACLMapProto> list = p.getApplicationACLsList();
  this.applicationACLS = new HashMap<ApplicationAccessType, String>(list
      .size());

  for (ApplicationACLMapProto aclProto : list) {
    this.applicationACLS.put(ProtoUtils.convertFromProtoFormat(aclProto
        .getAccessType()), aclProto.getAcl());
  }
}
 
Example #9
Source File: AllocateResponsePBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized AMCommand getAMCommand() {
  AllocateResponseProtoOrBuilder p = viaProto ? proto : builder;
  if (!p.hasAMCommand()) {
    return null;
  }
  return ProtoUtils.convertFromProtoFormat(p.getAMCommand());
}
 
Example #10
Source File: ApplicationAttemptStateDataPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public Credentials getAppAttemptTokens() {
  ApplicationAttemptStateDataProtoOrBuilder p = viaProto ? proto : builder;
  if(appAttemptTokens != null) {
    return convertCredentialsFromByteBuffer(appAttemptTokens);
  }
  if(!p.hasAppAttemptTokens()) {
    return null;
  }
  this.appAttemptTokens = ProtoUtils.convertFromProtoFormat(
      p.getAppAttemptTokens());
  return convertCredentialsFromByteBuffer(appAttemptTokens);
}
 
Example #11
Source File: ApplicationAttemptStateDataPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void mergeLocalToBuilder() {
  if (this.attemptId != null) {
    builder.setAttemptId(((ApplicationAttemptIdPBImpl)attemptId).getProto());
  }
  if(this.masterContainer != null) {
    builder.setMasterContainer(((ContainerPBImpl)masterContainer).getProto());
  }
  if(this.appAttemptTokens != null) {
    builder.setAppAttemptTokens(ProtoUtils.convertToProtoFormat(
        this.appAttemptTokens));
  }
}
 
Example #12
Source File: NodeHeartbeatResponsePBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void initSystemCredentials() {
  NodeHeartbeatResponseProtoOrBuilder p = viaProto ? proto : builder;
  List<SystemCredentialsForAppsProto> list = p.getSystemCredentialsForAppsList();
  this.systemCredentials = new HashMap<ApplicationId, ByteBuffer> ();
  for (SystemCredentialsForAppsProto c : list) {
    ApplicationId appId = convertFromProtoFormat(c.getAppId());
    ByteBuffer byteBuffer = ProtoUtils.convertFromProtoFormat(c.getCredentialsForApp());
    this.systemCredentials.put(appId, byteBuffer);
  }
}
 
Example #13
Source File: ContainerManagerImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private ContainerManagerApplicationProto buildAppProto(ApplicationId appId,
    String user, Credentials credentials,
    Map<ApplicationAccessType, String> appAcls,
    LogAggregationContext logAggregationContext) {

  ContainerManagerApplicationProto.Builder builder =
      ContainerManagerApplicationProto.newBuilder();
  builder.setId(((ApplicationIdPBImpl) appId).getProto());
  builder.setUser(user);

  if (logAggregationContext != null) {
    builder.setLogAggregationContext((
        (LogAggregationContextPBImpl)logAggregationContext).getProto());
  }

  builder.clearCredentials();
  if (credentials != null) {
    DataOutputBuffer dob = new DataOutputBuffer();
    try {
      credentials.writeTokenStorageToStream(dob);
      builder.setCredentials(ByteString.copyFrom(dob.getData()));
    } catch (IOException e) {
      // should not occur
      LOG.error("Cannot serialize credentials", e);
    }
  }

  builder.clearAcls();
  if (appAcls != null) {
    for (Map.Entry<ApplicationAccessType, String> acl : appAcls.entrySet()) {
      ApplicationACLMapProto p = ApplicationACLMapProto.newBuilder()
          .setAccessType(ProtoUtils.convertToProtoFormat(acl.getKey()))
          .setAcl(acl.getValue())
          .build();
      builder.addAcls(p);
    }
  }

  return builder.build();
}
 
Example #14
Source File: ContainerManagerImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void recoverApplication(ContainerManagerApplicationProto p)
    throws IOException {
  ApplicationId appId = new ApplicationIdPBImpl(p.getId());
  Credentials creds = new Credentials();
  creds.readTokenStorageStream(
      new DataInputStream(p.getCredentials().newInput()));

  List<ApplicationACLMapProto> aclProtoList = p.getAclsList();
  Map<ApplicationAccessType, String> acls =
      new HashMap<ApplicationAccessType, String>(aclProtoList.size());
  for (ApplicationACLMapProto aclProto : aclProtoList) {
    acls.put(ProtoUtils.convertFromProtoFormat(aclProto.getAccessType()),
        aclProto.getAcl());
  }

  LogAggregationContext logAggregationContext = null;
  if (p.getLogAggregationContext() != null) {
    logAggregationContext =
        new LogAggregationContextPBImpl(p.getLogAggregationContext());
  }

  LOG.info("Recovering application " + appId);
  ApplicationImpl app = new ApplicationImpl(dispatcher, p.getUser(), appId,
      creds, context);
  context.getApplications().put(appId, app);
  app.handle(new ApplicationInitEvent(appId, acls, logAggregationContext));
}
 
Example #15
Source File: ContainerManagerImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void recoverApplication(ContainerManagerApplicationProto p)
    throws IOException {
  ApplicationId appId = new ApplicationIdPBImpl(p.getId());
  Credentials creds = new Credentials();
  creds.readTokenStorageStream(
      new DataInputStream(p.getCredentials().newInput()));

  List<ApplicationACLMapProto> aclProtoList = p.getAclsList();
  Map<ApplicationAccessType, String> acls =
      new HashMap<ApplicationAccessType, String>(aclProtoList.size());
  for (ApplicationACLMapProto aclProto : aclProtoList) {
    acls.put(ProtoUtils.convertFromProtoFormat(aclProto.getAccessType()),
        aclProto.getAcl());
  }

  LogAggregationContext logAggregationContext = null;
  if (p.getLogAggregationContext() != null) {
    logAggregationContext =
        new LogAggregationContextPBImpl(p.getLogAggregationContext());
  }

  LOG.info("Recovering application " + appId);
  ApplicationImpl app = new ApplicationImpl(dispatcher, p.getUser(), appId,
      creds, context);
  context.getApplications().put(appId, app);
  app.handle(new ApplicationInitEvent(appId, acls, logAggregationContext));
}
 
Example #16
Source File: ContainerManagerImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private ContainerManagerApplicationProto buildAppProto(ApplicationId appId,
    String user, Credentials credentials,
    Map<ApplicationAccessType, String> appAcls,
    LogAggregationContext logAggregationContext) {

  ContainerManagerApplicationProto.Builder builder =
      ContainerManagerApplicationProto.newBuilder();
  builder.setId(((ApplicationIdPBImpl) appId).getProto());
  builder.setUser(user);

  if (logAggregationContext != null) {
    builder.setLogAggregationContext((
        (LogAggregationContextPBImpl)logAggregationContext).getProto());
  }

  builder.clearCredentials();
  if (credentials != null) {
    DataOutputBuffer dob = new DataOutputBuffer();
    try {
      credentials.writeTokenStorageToStream(dob);
      builder.setCredentials(ByteString.copyFrom(dob.getData()));
    } catch (IOException e) {
      // should not occur
      LOG.error("Cannot serialize credentials", e);
    }
  }

  builder.clearAcls();
  if (appAcls != null) {
    for (Map.Entry<ApplicationAccessType, String> acl : appAcls.entrySet()) {
      ApplicationACLMapProto p = ApplicationACLMapProto.newBuilder()
          .setAccessType(ProtoUtils.convertToProtoFormat(acl.getKey()))
          .setAcl(acl.getValue())
          .build();
      builder.addAcls(p);
    }
  }

  return builder.build();
}
 
Example #17
Source File: ApplicationAttemptStateDataPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void mergeLocalToBuilder() {
  if (this.attemptId != null) {
    builder.setAttemptId(((ApplicationAttemptIdPBImpl)attemptId).getProto());
  }
  if(this.masterContainer != null) {
    builder.setMasterContainer(((ContainerPBImpl)masterContainer).getProto());
  }
  if(this.appAttemptTokens != null) {
    builder.setAppAttemptTokens(ProtoUtils.convertToProtoFormat(
        this.appAttemptTokens));
  }
}
 
Example #18
Source File: ApplicationAttemptStateDataPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public Credentials getAppAttemptTokens() {
  ApplicationAttemptStateDataProtoOrBuilder p = viaProto ? proto : builder;
  if(appAttemptTokens != null) {
    return convertCredentialsFromByteBuffer(appAttemptTokens);
  }
  if(!p.hasAppAttemptTokens()) {
    return null;
  }
  this.appAttemptTokens = ProtoUtils.convertFromProtoFormat(
      p.getAppAttemptTokens());
  return convertCredentialsFromByteBuffer(appAttemptTokens);
}
 
Example #19
Source File: NodeHeartbeatResponsePBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void initSystemCredentials() {
  NodeHeartbeatResponseProtoOrBuilder p = viaProto ? proto : builder;
  List<SystemCredentialsForAppsProto> list = p.getSystemCredentialsForAppsList();
  this.systemCredentials = new HashMap<ApplicationId, ByteBuffer> ();
  for (SystemCredentialsForAppsProto c : list) {
    ApplicationId appId = convertFromProtoFormat(c.getAppId());
    ByteBuffer byteBuffer = ProtoUtils.convertFromProtoFormat(c.getCredentialsForApp());
    this.systemCredentials.put(appId, byteBuffer);
  }
}
 
Example #20
Source File: NodeHeartbeatResponsePBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void addSystemCredentialsToProto() {
  maybeInitBuilder();
  builder.clearSystemCredentialsForApps();
  for (Map.Entry<ApplicationId, ByteBuffer> entry : systemCredentials.entrySet()) {
    builder.addSystemCredentialsForApps(SystemCredentialsForAppsProto.newBuilder()
      .setAppId(convertToProtoFormat(entry.getKey()))
      .setCredentialsForApp(ProtoUtils.convertToProtoFormat(
          entry.getValue().duplicate())));
  }
}
 
Example #21
Source File: AllocateResponsePBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void setAMCommand(AMCommand command) {
  maybeInitBuilder();
  if (command == null) {
    builder.clearAMCommand();
    return;
  }
  builder.setAMCommand(ProtoUtils.convertToProtoFormat(command));
}
 
Example #22
Source File: AllocateResponsePBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized AMCommand getAMCommand() {
  AllocateResponseProtoOrBuilder p = viaProto ? proto : builder;
  if (!p.hasAMCommand()) {
    return null;
  }
  return ProtoUtils.convertFromProtoFormat(p.getAMCommand());
}
 
Example #23
Source File: GetApplicationsRequestPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void initScope() {
  if (this.scope != null) {
    return;
  }
  GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder;
  this.scope = ProtoUtils.convertFromProtoFormat(p.getScope());
}
 
Example #24
Source File: GetApplicationsRequestPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void initApplicationStates() {
  if (this.applicationStates != null) {
    return;
  }
  GetApplicationsRequestProtoOrBuilder p = viaProto ? proto : builder;
  List<YarnApplicationStateProto> appStatesList =
      p.getApplicationStatesList();
  this.applicationStates = EnumSet.noneOf(YarnApplicationState.class);

  for (YarnApplicationStateProto c : appStatesList) {
    this.applicationStates.add(ProtoUtils.convertFromProtoFormat(c));
  }
}
 
Example #25
Source File: RegisterApplicationMasterResponsePBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void initApplicationACLs() {
  if (this.applicationACLS != null) {
    return;
  }
  RegisterApplicationMasterResponseProtoOrBuilder p = viaProto ? proto
      : builder;
  List<ApplicationACLMapProto> list = p.getApplicationACLsList();
  this.applicationACLS = new HashMap<ApplicationAccessType, String>(list
      .size());

  for (ApplicationACLMapProto aclProto : list) {
    this.applicationACLS.put(ProtoUtils.convertFromProtoFormat(aclProto
        .getAccessType()), aclProto.getAcl());
  }
}
 
Example #26
Source File: RegisterApplicationMasterResponsePBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void addApplicationACLs() {
  maybeInitBuilder();
  builder.clearApplicationACLs();
  if (applicationACLS == null) {
    return;
  }
  Iterable<? extends ApplicationACLMapProto> values
      = new Iterable<ApplicationACLMapProto>() {

    @Override
    public Iterator<ApplicationACLMapProto> iterator() {
      return new Iterator<ApplicationACLMapProto>() {
        Iterator<ApplicationAccessType> aclsIterator = applicationACLS
            .keySet().iterator();

        @Override
        public boolean hasNext() {
          return aclsIterator.hasNext();
        }

        @Override
        public ApplicationACLMapProto next() {
          ApplicationAccessType key = aclsIterator.next();
          return ApplicationACLMapProto.newBuilder().setAcl(
              applicationACLS.get(key)).setAccessType(
              ProtoUtils.convertToProtoFormat(key)).build();
        }

        @Override
        public void remove() {
          throw new UnsupportedOperationException();
        }
      };
    }
  };
  this.builder.addAllApplicationACLs(values);
}
 
Example #27
Source File: GetClusterNodesRequestPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void mergeLocalToBuilder() {
  if (this.states != null) {
    maybeInitBuilder();
    builder.clearNodeStates();
    Iterable<NodeStateProto> iterable = new Iterable<NodeStateProto>() {
      @Override
      public Iterator<NodeStateProto> iterator() {
        return new Iterator<NodeStateProto>() {

          Iterator<NodeState> iter = states.iterator();

          @Override
          public boolean hasNext() {
            return iter.hasNext();
          }

          @Override
          public NodeStateProto next() {
            return ProtoUtils.convertToProtoFormat(iter.next());
          }

          @Override
          public void remove() {
            throw new UnsupportedOperationException();

          }
        };

      }
    };
    builder.addAllNodeStates(iterable);
  }
}
 
Example #28
Source File: NodeHeartbeatResponsePBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void addSystemCredentialsToProto() {
  maybeInitBuilder();
  builder.clearSystemCredentialsForApps();
  for (Map.Entry<ApplicationId, ByteBuffer> entry : systemCredentials.entrySet()) {
    builder.addSystemCredentialsForApps(SystemCredentialsForAppsProto.newBuilder()
      .setAppId(convertToProtoFormat(entry.getKey()))
      .setCredentialsForApp(ProtoUtils.convertToProtoFormat(
          entry.getValue().duplicate())));
  }
}
 
Example #29
Source File: GetApplicationsRequestPBImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void mergeLocalToBuilder() {
  if (applicationTypes != null && !applicationTypes.isEmpty()) {
    builder.clearApplicationTypes();
    builder.addAllApplicationTypes(applicationTypes);
  }
  if (applicationStates != null && !applicationStates.isEmpty()) {
    builder.clearApplicationStates();
    builder.addAllApplicationStates(Iterables.transform(applicationStates,
        new Function<YarnApplicationState, YarnApplicationStateProto>() {
          @Override
          public YarnApplicationStateProto apply(YarnApplicationState input) {
            return ProtoUtils.convertToProtoFormat(input);
          }
        }));
  }
  if (applicationTags != null && !applicationTags.isEmpty()) {
    builder.clearApplicationTags();
    builder.addAllApplicationTags(this.applicationTags);
  }
  if (scope != null) {
    builder.setScope(ProtoUtils.convertToProtoFormat(scope));
  }
  if (start != null) {
    builder.setStartBegin(start.getMinimumLong());
    builder.setStartEnd(start.getMaximumLong());
  }
  if (finish != null) {
    builder.setFinishBegin(finish.getMinimumLong());
    builder.setFinishEnd(finish.getMaximumLong());
  }
  if (limit != Long.MAX_VALUE) {
    builder.setLimit(limit);
  }
  if (users != null && !users.isEmpty()) {
    builder.clearUsers();
    builder.addAllUsers(users);
  }
  if (queues != null && !queues.isEmpty()) {
    builder.clearQueues();
    builder.addAllQueues(queues);
  }
}
 
Example #30
Source File: ApplicationFinishDataPBImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
private YarnApplicationState convertFromProtoFormat(
    YarnApplicationStateProto yarnApplicationState) {
  return ProtoUtils.convertFromProtoFormat(yarnApplicationState);
}