Search in sources :

Example 1 with ResourcePBImpl

use of org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl in project hadoop by apache.

the class NMLeveldbStateStoreService method storeContainerResourceChanged.

@Override
public void storeContainerResourceChanged(ContainerId containerId, int containerVersion, Resource capability) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("storeContainerResourceChanged: containerId=" + containerId + ", capability=" + capability);
    }
    String keyResChng = CONTAINERS_KEY_PREFIX + containerId.toString() + CONTAINER_RESOURCE_CHANGED_KEY_SUFFIX;
    String keyVersion = CONTAINERS_KEY_PREFIX + containerId.toString() + CONTAINER_VERSION_KEY_SUFFIX;
    try {
        WriteBatch batch = db.createWriteBatch();
        try {
            // New value will overwrite old values for the same key
            batch.put(bytes(keyResChng), ((ResourcePBImpl) capability).getProto().toByteArray());
            batch.put(bytes(keyVersion), bytes(Integer.toString(containerVersion)));
            db.write(batch);
        } finally {
            batch.close();
        }
    } catch (DBException e) {
        throw new IOException(e);
    }
}
Also used : DBException(org.iq80.leveldb.DBException) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) IOException(java.io.IOException) WriteBatch(org.iq80.leveldb.WriteBatch) ResourcePBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl)

Example 2 with ResourcePBImpl

use of org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl in project hadoop by apache.

the class TestReservationSystemUtil method createResource.

public Resource createResource(int memory, int vCores) {
    Resource resource = new ResourcePBImpl();
    resource.setMemorySize(memory);
    resource.setVirtualCores(vCores);
    return resource;
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource) ResourcePBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl)

Example 3 with ResourcePBImpl

use of org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl in project hadoop by apache.

the class NMLeveldbStateStoreService method loadContainerState.

private RecoveredContainerState loadContainerState(ContainerId containerId, LeveldbIterator iter, String keyPrefix) throws IOException {
    RecoveredContainerState rcs = new RecoveredContainerState();
    rcs.status = RecoveredContainerStatus.REQUESTED;
    while (iter.hasNext()) {
        Entry<byte[], byte[]> entry = iter.peekNext();
        String key = asString(entry.getKey());
        if (!key.startsWith(keyPrefix)) {
            break;
        }
        iter.next();
        // start with '/'
        String suffix = key.substring(keyPrefix.length() - 1);
        if (suffix.equals(CONTAINER_REQUEST_KEY_SUFFIX)) {
            rcs.startRequest = new StartContainerRequestPBImpl(StartContainerRequestProto.parseFrom(entry.getValue()));
        } else if (suffix.equals(CONTAINER_VERSION_KEY_SUFFIX)) {
            rcs.version = Integer.parseInt(asString(entry.getValue()));
        } else if (suffix.equals(CONTAINER_DIAGS_KEY_SUFFIX)) {
            rcs.diagnostics = asString(entry.getValue());
        } else if (suffix.equals(CONTAINER_QUEUED_KEY_SUFFIX)) {
            if (rcs.status == RecoveredContainerStatus.REQUESTED) {
                rcs.status = RecoveredContainerStatus.QUEUED;
            }
        } else if (suffix.equals(CONTAINER_LAUNCHED_KEY_SUFFIX)) {
            if ((rcs.status == RecoveredContainerStatus.REQUESTED) || (rcs.status == RecoveredContainerStatus.QUEUED)) {
                rcs.status = RecoveredContainerStatus.LAUNCHED;
            }
        } else if (suffix.equals(CONTAINER_KILLED_KEY_SUFFIX)) {
            rcs.killed = true;
        } else if (suffix.equals(CONTAINER_EXIT_CODE_KEY_SUFFIX)) {
            rcs.status = RecoveredContainerStatus.COMPLETED;
            rcs.exitCode = Integer.parseInt(asString(entry.getValue()));
        } else if (suffix.equals(CONTAINER_RESOURCE_CHANGED_KEY_SUFFIX)) {
            rcs.capability = new ResourcePBImpl(ResourceProto.parseFrom(entry.getValue()));
        } else if (suffix.equals(CONTAINER_REMAIN_RETRIES_KEY_SUFFIX)) {
            rcs.setRemainingRetryAttempts(Integer.parseInt(asString(entry.getValue())));
        } else if (suffix.equals(CONTAINER_WORK_DIR_KEY_SUFFIX)) {
            rcs.setWorkDir(asString(entry.getValue()));
        } else if (suffix.equals(CONTAINER_LOG_DIR_KEY_SUFFIX)) {
            rcs.setLogDir(asString(entry.getValue()));
        } else {
            LOG.warn("the container " + containerId + " will be killed because of the unknown key " + key + " during recovery.");
            containerUnknownKeySuffixes.put(containerId, suffix);
            rcs.setRecoveryType(RecoveredContainerType.KILL);
        }
    }
    return rcs;
}
Also used : StartContainerRequestPBImpl(org.apache.hadoop.yarn.api.protocolrecords.impl.pb.StartContainerRequestPBImpl) JniDBFactory.asString(org.fusesource.leveldbjni.JniDBFactory.asString) ResourcePBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl)

Aggregations

ResourcePBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ResourcePBImpl)3 JniDBFactory.asString (org.fusesource.leveldbjni.JniDBFactory.asString)2 IOException (java.io.IOException)1 StartContainerRequestPBImpl (org.apache.hadoop.yarn.api.protocolrecords.impl.pb.StartContainerRequestPBImpl)1 Resource (org.apache.hadoop.yarn.api.records.Resource)1 DBException (org.iq80.leveldb.DBException)1 WriteBatch (org.iq80.leveldb.WriteBatch)1