Search in sources :

Example 6 with NetworkAddress

use of org.apache.hyracks.api.comm.NetworkAddress in project asterixdb by apache.

the class NodeManagerTest method mockNodeControllerState.

private NodeControllerState mockNodeControllerState(String nodeId, boolean invalidIpAddr) {
    NodeControllerState ncState = mock(NodeControllerState.class);
    String ipAddr = invalidIpAddr ? "255.255.255:255" : "127.0.0.2";
    NetworkAddress dataAddr = new NetworkAddress(ipAddr, 1001);
    NetworkAddress resultAddr = new NetworkAddress(ipAddr, 1002);
    NetworkAddress msgAddr = new NetworkAddress(ipAddr, 1003);
    when(ncState.getCapacity()).thenReturn(new NodeCapacity(NODE_MEMORY_SIZE, NODE_CORES));
    when(ncState.getDataPort()).thenReturn(dataAddr);
    when(ncState.getDatasetPort()).thenReturn(resultAddr);
    when(ncState.getMessagingPort()).thenReturn(msgAddr);
    NCConfig ncConfig = new NCConfig(nodeId);
    ncConfig.setDataPublicAddress(ipAddr);
    when(ncState.getNCConfig()).thenReturn(ncConfig);
    return ncState;
}
Also used : NetworkAddress(org.apache.hyracks.api.comm.NetworkAddress) NodeCapacity(org.apache.hyracks.api.job.resource.NodeCapacity) NCConfig(org.apache.hyracks.control.common.controllers.NCConfig) NodeControllerState(org.apache.hyracks.control.cc.NodeControllerState)

Example 7 with NetworkAddress

use of org.apache.hyracks.api.comm.NetworkAddress in project asterixdb by apache.

the class ConnectorApiServletTest method testFormResponseObject.

@Test
public void testFormResponseObject() throws Exception {
    ConnectorApiServlet let = new ConnectorApiServlet(new ConcurrentHashMap<>(), new String[] { "/" }, (ICcApplicationContext) ExecutionTestUtil.integrationUtil.cc.getApplicationContext());
    ObjectMapper om = new ObjectMapper();
    ObjectNode actualResponse = om.createObjectNode();
    FileSplit[] splits = new FileSplit[2];
    splits[0] = new ManagedFileSplit("asterix_nc1", "foo1");
    splits[1] = new ManagedFileSplit("asterix_nc2", "foo2");
    Map<String, NodeControllerInfo> nodeMap = new HashMap<>();
    NodeControllerInfo mockInfo1 = mock(NodeControllerInfo.class);
    NodeControllerInfo mockInfo2 = mock(NodeControllerInfo.class);
    // Sets up mock returns.
    when(mockInfo1.getNetworkAddress()).thenReturn(new NetworkAddress("127.0.0.1", 3099));
    when(mockInfo2.getNetworkAddress()).thenReturn(new NetworkAddress("127.0.0.2", 3099));
    String[] fieldNames = new String[] { "a1", "a2" };
    IAType[] fieldTypes = new IAType[] { BuiltinType.ABOOLEAN, BuiltinType.ADAYTIMEDURATION };
    ARecordType recordType = new ARecordType("record", fieldNames, fieldTypes, true);
    String primaryKey = "a1";
    // Calls ConnectorAPIServlet.formResponseObject.
    nodeMap.put("asterix_nc1", mockInfo1);
    nodeMap.put("asterix_nc2", mockInfo2);
    PA.invokeMethod(let, "formResponseObject(" + ObjectNode.class.getName() + ", " + FileSplit.class.getName() + "[], " + ARecordType.class.getName() + ", " + String.class.getName() + ", boolean, " + Map.class.getName() + ")", actualResponse, splits, recordType, primaryKey, true, nodeMap);
    // Constructs expected response.
    ObjectNode expectedResponse = om.createObjectNode();
    expectedResponse.put("temp", true);
    expectedResponse.put("keys", primaryKey);
    expectedResponse.set("type", recordType.toJSON());
    ArrayNode splitsArray = om.createArrayNode();
    ObjectNode element1 = om.createObjectNode();
    element1.put("ip", "127.0.0.1");
    element1.put("path", splits[0].getPath());
    ObjectNode element2 = om.createObjectNode();
    element2.put("ip", "127.0.0.2");
    element2.put("path", splits[1].getPath());
    splitsArray.add(element1);
    splitsArray.add(element2);
    expectedResponse.set("splits", splitsArray);
    // Checks results.
    Assert.assertEquals(actualResponse.toString(), expectedResponse.toString());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ManagedFileSplit(org.apache.hyracks.api.io.ManagedFileSplit) FileSplit(org.apache.hyracks.api.io.FileSplit) ManagedFileSplit(org.apache.hyracks.api.io.ManagedFileSplit) NetworkAddress(org.apache.hyracks.api.comm.NetworkAddress) NodeControllerInfo(org.apache.hyracks.api.client.NodeControllerInfo) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ConnectorApiServlet(org.apache.asterix.api.http.server.ConnectorApiServlet) ARecordType(org.apache.asterix.om.types.ARecordType) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IAType(org.apache.asterix.om.types.IAType) Test(org.junit.Test) SqlppExecutionTest(org.apache.asterix.test.runtime.SqlppExecutionTest)

Example 8 with NetworkAddress

use of org.apache.hyracks.api.comm.NetworkAddress in project asterixdb by apache.

the class NodeControllerService method start.

@Override
public void start() throws Exception {
    LOGGER.log(Level.INFO, "Starting NodeControllerService");
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Setting uncaught exception handler " + getLifeCycleComponentManager());
    }
    Thread.currentThread().setUncaughtExceptionHandler(getLifeCycleComponentManager());
    Runtime.getRuntime().addShutdownHook(new NCShutdownHook(this));
    ipc = new IPCSystem(new InetSocketAddress(ncConfig.getClusterListenAddress(), ncConfig.getClusterListenPort()), new NodeControllerIPCI(this), new CCNCFunctions.SerializerDeserializer());
    ipc.start();
    partitionManager = new PartitionManager(this);
    netManager = new NetworkManager(ncConfig.getDataListenAddress(), ncConfig.getDataListenPort(), partitionManager, ncConfig.getNetThreadCount(), ncConfig.getNetBufferCount(), ncConfig.getDataPublicAddress(), ncConfig.getDataPublicPort(), FullFrameChannelInterfaceFactory.INSTANCE);
    netManager.start();
    startApplication();
    init();
    datasetNetworkManager.start();
    if (messagingNetManager != null) {
        messagingNetManager.start();
    }
    IIPCHandle ccIPCHandle = ipc.getHandle(new InetSocketAddress(ncConfig.getClusterAddress(), ncConfig.getClusterPort()), ncConfig.getClusterConnectRetries());
    this.ccs = new ClusterControllerRemoteProxy(ccIPCHandle);
    HeartbeatSchema.GarbageCollectorInfo[] gcInfos = new HeartbeatSchema.GarbageCollectorInfo[gcMXBeans.size()];
    for (int i = 0; i < gcInfos.length; ++i) {
        gcInfos[i] = new HeartbeatSchema.GarbageCollectorInfo(gcMXBeans.get(i).getName());
    }
    HeartbeatSchema hbSchema = new HeartbeatSchema(gcInfos);
    // Use "public" versions of network addresses and ports
    NetworkAddress datasetAddress = datasetNetworkManager.getPublicNetworkAddress();
    NetworkAddress netAddress = netManager.getPublicNetworkAddress();
    NetworkAddress meesagingPort = messagingNetManager != null ? messagingNetManager.getPublicNetworkAddress() : null;
    int allCores = osMXBean.getAvailableProcessors();
    ccs.registerNode(new NodeRegistration(ipc.getSocketAddress(), id, ncConfig, netAddress, datasetAddress, osMXBean.getName(), osMXBean.getArch(), osMXBean.getVersion(), allCores, runtimeMXBean.getVmName(), runtimeMXBean.getVmVersion(), runtimeMXBean.getVmVendor(), runtimeMXBean.getClassPath(), runtimeMXBean.getLibraryPath(), runtimeMXBean.getBootClassPath(), runtimeMXBean.getInputArguments(), runtimeMXBean.getSystemProperties(), hbSchema, meesagingPort, application.getCapacity(), PidHelper.getPid()));
    synchronized (this) {
        while (registrationPending) {
            wait();
        }
    }
    if (registrationException != null) {
        throw registrationException;
    }
    serviceCtx.setDistributedState(nodeParameters.getDistributedState());
    workQueue.start();
    heartbeatTask = new HeartbeatTask(ccs);
    // Use reflection to set the priority of the timer thread.
    Field threadField = timer.getClass().getDeclaredField("thread");
    threadField.setAccessible(true);
    // The internal timer thread of the Timer object.
    Thread timerThread = (Thread) threadField.get(timer);
    timerThread.setPriority(Thread.MAX_PRIORITY);
    // Schedule heartbeat generator.
    timer.schedule(heartbeatTask, 0, nodeParameters.getHeartbeatPeriod());
    if (nodeParameters.getProfileDumpPeriod() > 0) {
        // Schedule profile dump generator.
        timer.schedule(new ProfileDumpTask(ccs), 0, nodeParameters.getProfileDumpPeriod());
    }
    LOGGER.log(Level.INFO, "Started NodeControllerService");
    application.startupCompleted();
}
Also used : IIPCHandle(org.apache.hyracks.ipc.api.IIPCHandle) NodeRegistration(org.apache.hyracks.control.common.controllers.NodeRegistration) PartitionManager(org.apache.hyracks.control.nc.partitions.PartitionManager) DatasetPartitionManager(org.apache.hyracks.control.nc.dataset.DatasetPartitionManager) IDatasetPartitionManager(org.apache.hyracks.api.dataset.IDatasetPartitionManager) InetSocketAddress(java.net.InetSocketAddress) IPCSystem(org.apache.hyracks.ipc.impl.IPCSystem) ClusterControllerRemoteProxy(org.apache.hyracks.control.common.ipc.ClusterControllerRemoteProxy) Field(java.lang.reflect.Field) NetworkAddress(org.apache.hyracks.api.comm.NetworkAddress) DatasetNetworkManager(org.apache.hyracks.control.nc.net.DatasetNetworkManager) MessagingNetworkManager(org.apache.hyracks.control.nc.net.MessagingNetworkManager) NetworkManager(org.apache.hyracks.control.nc.net.NetworkManager) HeartbeatSchema(org.apache.hyracks.control.common.heartbeat.HeartbeatSchema)

Example 9 with NetworkAddress

use of org.apache.hyracks.api.comm.NetworkAddress in project asterixdb by apache.

the class CCNCFunctions method readNetworkAddress.

private static NetworkAddress readNetworkAddress(DataInputStream dis) throws IOException {
    String address = dis.readUTF();
    int port = dis.readInt();
    NetworkAddress networkAddress = new NetworkAddress(address, port);
    return networkAddress;
}
Also used : NetworkAddress(org.apache.hyracks.api.comm.NetworkAddress)

Example 10 with NetworkAddress

use of org.apache.hyracks.api.comm.NetworkAddress in project asterixdb by apache.

the class DatasetNetworkManager method start.

public void start() throws IOException {
    md.start();
    InetSocketAddress sockAddr = md.getLocalAddress();
    localNetworkAddress = new NetworkAddress(sockAddr.getHostString(), sockAddr.getPort());
    // make it a copy of localNetworkAddress
    if (publicNetworkAddress.getAddress() == null) {
        publicNetworkAddress = localNetworkAddress;
    } else {
        // Likewise for public port
        if (publicNetworkAddress.getPort() == 0) {
            publicNetworkAddress = new NetworkAddress(publicNetworkAddress.getAddress(), sockAddr.getPort());
        }
    }
}
Also used : NetworkAddress(org.apache.hyracks.api.comm.NetworkAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

NetworkAddress (org.apache.hyracks.api.comm.NetworkAddress)15 InetSocketAddress (java.net.InetSocketAddress)6 NodeControllerInfo (org.apache.hyracks.api.client.NodeControllerInfo)5 HashMap (java.util.HashMap)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConnectorApiServlet (org.apache.asterix.api.http.server.ConnectorApiServlet)2 ARecordType (org.apache.asterix.om.types.ARecordType)2 SqlppExecutionTest (org.apache.asterix.test.runtime.SqlppExecutionTest)2 NodeControllerState (org.apache.hyracks.control.cc.NodeControllerState)2 INodeManager (org.apache.hyracks.control.cc.cluster.INodeManager)2 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 Field (java.lang.reflect.Field)1