Search in sources :

Example 1 with ContainerContext

use of com.datatorrent.stram.api.ContainerContext in project apex-core by apache.

the class StreamingContainer method setup.

@SuppressWarnings("unchecked")
public void setup(StreamingContainerContext ctx) {
    containerContext = ctx;
    /* add a request factory local to this container */
    this.requestFactory = new RequestFactory();
    ctx.attributes.put(ContainerContext.REQUEST_FACTORY, requestFactory);
    heartbeatIntervalMillis = ctx.getValue(Context.DAGContext.HEARTBEAT_INTERVAL_MILLIS);
    firstWindowMillis = ctx.startWindowMillis;
    windowWidthMillis = ctx.getValue(Context.DAGContext.STREAMING_WINDOW_SIZE_MILLIS);
    checkpointWindowCount = ctx.getValue(Context.DAGContext.CHECKPOINT_WINDOW_COUNT);
    fastPublisherSubscriber = ctx.getValue(LogicalPlan.FAST_PUBLISHER_SUBSCRIBER);
    Map<Class<?>, Class<? extends StringCodec<?>>> codecs = ctx.getValue(Context.DAGContext.STRING_CODECS);
    StringCodecs.loadConverters(codecs);
    try {
        if (ctx.deployBufferServer) {
            eventloop.start();
            int bufferServerRAM = ctx.getValue(ContainerContext.BUFFER_SERVER_MB);
            logger.debug("buffer server memory {}", bufferServerRAM);
            int blockCount;
            int blocksize;
            if (bufferServerRAM < ContainerContext.BUFFER_SERVER_MB.defaultValue) {
                blockCount = 8;
                blocksize = bufferServerRAM / blockCount;
                if (blocksize < 1) {
                    blocksize = 1;
                }
            } else {
                blocksize = 64;
                blockCount = bufferServerRAM / blocksize;
            }
            // start buffer server, if it was not set externally
            bufferServer = new Server(eventloop, 0, blocksize * 1024 * 1024, blockCount);
            bufferServer.setAuthToken(ctx.getValue(StreamingContainerContext.BUFFER_SERVER_TOKEN));
            if (ctx.getValue(Context.DAGContext.BUFFER_SPOOLING)) {
                bufferServer.setSpoolStorage(new DiskStorage());
            }
            bufferServerAddress = NetUtils.getConnectAddress(bufferServer.run());
            logger.debug("Buffer server started: {}", bufferServerAddress);
        }
    } catch (IOException ex) {
        logger.warn("deploy request failed due to {}", ex);
        throw new IllegalStateException("Failed to deploy buffer server", ex);
    }
    for (Class<?> clazz : ContainerEvent.CONTAINER_EVENTS_LISTENERS) {
        try {
            Object newInstance = clazz.newInstance();
            singletons.put(clazz.getName(), newInstance);
            if (newInstance instanceof Component) {
                components.add((Component<ContainerContext>) newInstance);
            }
            eventBus.subscribe(newInstance);
        } catch (InstantiationException ex) {
            logger.warn("Container Event Listener Instantiation", ex);
        } catch (IllegalAccessException ex) {
            logger.warn("Container Event Listener Instantiation", ex);
        }
    }
    operateListeners(ctx, true);
}
Also used : Server(com.datatorrent.bufferserver.server.Server) IOException(java.io.IOException) Checkpoint(com.datatorrent.stram.api.Checkpoint) ContainerContext(com.datatorrent.stram.api.ContainerContext) StreamingContainerContext(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.StreamingContainerContext) StringCodec(com.datatorrent.api.StringCodec) RequestFactory(com.datatorrent.stram.api.RequestFactory) Component(com.datatorrent.api.Component) DiskStorage(com.datatorrent.bufferserver.storage.DiskStorage)

Example 2 with ContainerContext

use of com.datatorrent.stram.api.ContainerContext in project apex-core by apache.

the class StreamingContainer method deployNodes.

private void deployNodes(List<OperatorDeployInfo> nodeList) throws IOException {
    for (OperatorDeployInfo ndi : nodeList) {
        StorageAgent backupAgent = getValue(OperatorContext.STORAGE_AGENT, ndi);
        assert (backupAgent != null);
        Context parentContext;
        if (ndi instanceof UnifierDeployInfo) {
            OperatorContext unifiedOperatorContext = new OperatorContext(0, ndi.name, ((UnifierDeployInfo) ndi).operatorAttributes, containerContext);
            parentContext = new PortContext(ndi.inputs.get(0).contextAttributes, unifiedOperatorContext);
            massageUnifierDeployInfo(ndi);
        } else {
            parentContext = containerContext;
        }
        OperatorContext ctx = new OperatorContext(ndi.id, ndi.name, ndi.contextAttributes, parentContext);
        ctx.attributes.put(OperatorContext.ACTIVATION_WINDOW_ID, ndi.checkpoint.windowId);
        Node<?> node = reuseOpNodes.get(ndi.id);
        if (node == null) {
            logger.info("Restoring operator {} to checkpoint {} stateless={}.", ndi.id, Codec.getStringWindowId(ndi.checkpoint.windowId), ctx.stateless);
            node = Node.retrieveNode(backupAgent.load(ndi.id, ctx.stateless ? Stateless.WINDOW_ID : ndi.checkpoint.windowId), ctx, ndi.type);
        } else {
            logger.info("Reusing previous operator instance {}", ndi.id);
            node = Node.retrieveNode(node.operator, ctx, ndi.type);
            node.setReuseOperator(true);
            reuseOpNodes.remove(ndi.id);
        }
        node.currentWindowId = ndi.checkpoint.windowId;
        node.applicationWindowCount = ndi.checkpoint.applicationWindowCount;
        node.firstWindowMillis = firstWindowMillis;
        node.windowWidthMillis = windowWidthMillis;
        node.setId(ndi.id);
        nodes.put(ndi.id, node);
        logger.debug("Marking operator {} as deployed.", node);
    }
}
Also used : Context(com.datatorrent.api.Context) ContainerContext(com.datatorrent.stram.api.ContainerContext) StreamingContainerContext(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.StreamingContainerContext) OperatorDeployInfo(com.datatorrent.stram.api.OperatorDeployInfo) StorageAgent(com.datatorrent.api.StorageAgent) UnifierDeployInfo(com.datatorrent.stram.api.OperatorDeployInfo.UnifierDeployInfo)

Aggregations

ContainerContext (com.datatorrent.stram.api.ContainerContext)2 StreamingContainerContext (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.StreamingContainerContext)2 Component (com.datatorrent.api.Component)1 Context (com.datatorrent.api.Context)1 StorageAgent (com.datatorrent.api.StorageAgent)1 StringCodec (com.datatorrent.api.StringCodec)1 Server (com.datatorrent.bufferserver.server.Server)1 DiskStorage (com.datatorrent.bufferserver.storage.DiskStorage)1 Checkpoint (com.datatorrent.stram.api.Checkpoint)1 OperatorDeployInfo (com.datatorrent.stram.api.OperatorDeployInfo)1 UnifierDeployInfo (com.datatorrent.stram.api.OperatorDeployInfo.UnifierDeployInfo)1 RequestFactory (com.datatorrent.stram.api.RequestFactory)1 IOException (java.io.IOException)1