Search in sources :

Example 1 with WorkerConnector

use of org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector in project rocketmq-externals by apache.

the class DefaultConnectorContext method requestTaskReconfiguration.

@Override
public void requestTaskReconfiguration() {
    Set<WorkerConnector> connectors = controller.getWorker().getWorkingConnectors();
    WorkerConnector currentConnector = null;
    for (WorkerConnector workerConnector : connectors) {
        if (workerConnector.getConnectorName().equals(connectorName)) {
            currentConnector = workerConnector;
        }
    }
    if (null != currentConnector) {
        Connector connector = currentConnector.getConnector();
        controller.getConfigManagementService().recomputeTaskConfigs(connectorName, connector, System.currentTimeMillis());
        log.info("Connector {} recompute taskConfigs success.", connectorName);
    } else {
        log.info("Not found connector {}.", connectorName);
    }
}
Also used : WorkerConnector(org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector) WorkerConnector(org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector) Connector(io.openmessaging.connector.api.Connector)

Example 2 with WorkerConnector

use of org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector in project rocketmq-externals by apache.

the class RestHandlerTest method init.

@Before
public void init() throws Exception {
    workerState = new AtomicReference<>(WorkerState.STARTED);
    when(connectController.getConnectConfig()).thenReturn(connectConfig);
    when(connectConfig.getHttpPort()).thenReturn(8081);
    when(connectController.getConfigManagementService()).thenReturn(configManagementService);
    when(configManagementService.putConnectorConfig(anyString(), any(ConnectKeyValue.class))).thenReturn("");
    String connectName = "testConnector";
    ConnectKeyValue connectKeyValue = new ConnectKeyValue();
    connectKeyValue.put(RuntimeConfigDefine.CONNECTOR_CLASS, "org.apache.rocketmq.connect.runtime.service.TestConnector");
    connectKeyValue.put(RuntimeConfigDefine.SOURCE_RECORD_CONVERTER, "source-record-converter");
    ConnectKeyValue connectKeyValue1 = new ConnectKeyValue();
    connectKeyValue1.put(RuntimeConfigDefine.CONNECTOR_CLASS, "org.apache.rocketmq.connect.runtime.service.TestConnector");
    connectKeyValue1.put(RuntimeConfigDefine.SOURCE_RECORD_CONVERTER, "source-record-converter1");
    List<ConnectKeyValue> connectKeyValues = new ArrayList<ConnectKeyValue>(8) {

        {
            add(connectKeyValue);
        }
    };
    connectorConfigs = new HashMap<String, ConnectKeyValue>() {

        {
            put(connectName, connectKeyValue);
        }
    };
    taskConfigs = new HashMap<String, List<ConnectKeyValue>>() {

        {
            put(connectName, connectKeyValues);
        }
    };
    when(configManagementService.getConnectorConfigs()).thenReturn(connectorConfigs);
    when(configManagementService.getTaskConfigs()).thenReturn(taskConfigs);
    aliveWorker = new ArrayList<String>() {

        {
            add("workerId1");
            add("workerId2");
        }
    };
    when(connectController.getClusterManagementService()).thenReturn(clusterManagementService);
    when(clusterManagementService.getAllAliveWorkers()).thenReturn(aliveWorker);
    sourcePartition = "127.0.0.13306".getBytes("UTF-8");
    JSONObject jsonObject = new JSONObject();
    // jsonObject.put(MysqlConstants.BINLOG_FILENAME, "binlogFilename");
    // jsonObject.put(MysqlConstants.NEXT_POSITION, "100");
    sourcePosition = jsonObject.toJSONString().getBytes();
    positions = new HashMap<ByteBuffer, ByteBuffer>() {

        {
            put(ByteBuffer.wrap(sourcePartition), ByteBuffer.wrap(sourcePosition));
        }
    };
    WorkerConnector workerConnector1 = new WorkerConnector("testConnectorName1", connector, connectKeyValue, new DefaultConnectorContext("testConnectorName1", connectController));
    WorkerConnector workerConnector2 = new WorkerConnector("testConnectorName2", connector, connectKeyValue1, new DefaultConnectorContext("testConnectorName2", connectController));
    workerConnectors = new HashSet<WorkerConnector>() {

        {
            add(workerConnector1);
            add(workerConnector2);
        }
    };
    WorkerSourceTask workerSourceTask1 = new WorkerSourceTask("testConnectorName1", sourceTask, connectKeyValue, positionManagementServiceImpl, converter, producer, workerState);
    WorkerSourceTask workerSourceTask2 = new WorkerSourceTask("testConnectorName2", sourceTask, connectKeyValue1, positionManagementServiceImpl, converter, producer, workerState);
    workerTasks = new HashSet<Runnable>() {

        {
            add(workerSourceTask1);
            add(workerSourceTask2);
        }
    };
    when(connectController.getWorker()).thenReturn(worker);
    when(worker.getWorkingConnectors()).thenReturn(workerConnectors);
    when(worker.getWorkingTasks()).thenReturn(workerTasks);
    restHandler = new RestHandler(connectController);
    httpClient = HttpClientBuilder.create().build();
}
Also used : WorkerConnector(org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector) WorkerSourceTask(org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerSourceTask) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) ByteBuffer(java.nio.ByteBuffer) ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) DefaultConnectorContext(org.apache.rocketmq.connect.runtime.service.DefaultConnectorContext) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) Before(org.junit.Before)

Example 3 with WorkerConnector

use of org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector in project rocketmq-externals by apache.

the class RestHandlerTest method testRESTful.

@Test
public void testRESTful() throws Exception {
    URIBuilder uriBuilder = new URIBuilder(String.format(CREATE_CONNECTOR_URL, "testConnectorName"));
    uriBuilder.setParameter("config", "{\"connector-class\": \"org.apache.rocketmq.connect.runtime.connectorwrapper.testimpl.TestConnector\",\"mysqlAddr\": \"112.74.179.68\",\"mysqlPort\": \"3306\",\"mysqlUsername\": \"canal\",\"mysqlPassword\": \"canal\",\"source-record-converter\":\"org.apache.rocketmq.connect.runtime.converter.JsonConverter\"}");
    URI uri = uriBuilder.build();
    HttpGet httpGet = new HttpGet(uri);
    HttpResponse httpResponse = httpClient.execute(httpGet);
    assertEquals(200, httpResponse.getStatusLine().getStatusCode());
    assertEquals("success", EntityUtils.toString(httpResponse.getEntity(), "UTF-8"));
    URIBuilder uriBuilder1 = new URIBuilder(String.format(STOP_CONNECTOR_URL, "testConnectorName"));
    URI uri1 = uriBuilder1.build();
    HttpGet httpGet1 = new HttpGet(uri1);
    HttpResponse httpResponse1 = httpClient.execute(httpGet1);
    assertEquals(200, httpResponse1.getStatusLine().getStatusCode());
    assertEquals("success", EntityUtils.toString(httpResponse1.getEntity(), "UTF-8"));
    URIBuilder uriBuilder2 = new URIBuilder(GET_CLUSTER_INFO_URL);
    URI uri2 = uriBuilder2.build();
    HttpGet httpGet2 = new HttpGet(uri2);
    HttpResponse httpResponse2 = httpClient.execute(httpGet2);
    assertEquals(200, httpResponse2.getStatusLine().getStatusCode());
    assertEquals(JSON.toJSONString(aliveWorker), EntityUtils.toString(httpResponse2.getEntity(), "UTF-8"));
    URIBuilder uriBuilder3 = new URIBuilder(GET_CONFIG_INFO_URL);
    URI uri3 = uriBuilder3.build();
    HttpGet httpGet3 = new HttpGet(uri3);
    HttpResponse httpResponse3 = httpClient.execute(httpGet3);
    assertEquals(200, httpResponse3.getStatusLine().getStatusCode());
    Map<String, Map> formatter = new HashMap<>();
    formatter.put("connectorConfigs", connectorConfigs);
    formatter.put("taskConfigs", taskConfigs);
    assertEquals(JSON.toJSONString(formatter), EntityUtils.toString(httpResponse3.getEntity(), "UTF-8"));
    URIBuilder uriBuilder4 = new URIBuilder(GET_ALLOCATED_CONNECTORS_URL);
    URI uri4 = uriBuilder4.build();
    HttpGet httpGet4 = new HttpGet(uri4);
    HttpResponse httpResponse4 = httpClient.execute(httpGet4);
    assertEquals(200, httpResponse4.getStatusLine().getStatusCode());
    Map<String, ConnectKeyValue> connectors = new HashMap<>();
    for (WorkerConnector workerConnector : workerConnectors) {
        connectors.put(workerConnector.getConnectorName(), workerConnector.getKeyValue());
    }
    assertEquals(JSON.toJSONString(connectors), EntityUtils.toString(httpResponse4.getEntity(), "UTF-8"));
}
Also used : WorkerConnector(org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector) ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) HashMap(java.util.HashMap) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Mockito.anyString(org.mockito.Mockito.anyString) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) URIBuilder(org.apache.http.client.utils.URIBuilder) Test(org.junit.Test)

Example 4 with WorkerConnector

use of org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector in project rocketmq-externals by apache.

the class RestHandler method getAllocatedConnectors.

private void getAllocatedConnectors(Context context) {
    Set<WorkerConnector> workerConnectors = connectController.getWorker().getWorkingConnectors();
    Set<Runnable> workerTasks = connectController.getWorker().getWorkingTasks();
    Map<String, ConnectKeyValue> connectors = new HashMap<>();
    for (WorkerConnector workerConnector : workerConnectors) {
        connectors.put(workerConnector.getConnectorName(), workerConnector.getKeyValue());
    }
    context.result(JSON.toJSONString(connectors));
}
Also used : WorkerConnector(org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector) ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) HashMap(java.util.HashMap)

Aggregations

WorkerConnector (org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector)4 ConnectKeyValue (org.apache.rocketmq.connect.runtime.common.ConnectKeyValue)3 HashMap (java.util.HashMap)2 Mockito.anyString (org.mockito.Mockito.anyString)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Connector (io.openmessaging.connector.api.Connector)1 URI (java.net.URI)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 HttpResponse (org.apache.http.HttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 WorkerSourceTask (org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerSourceTask)1 DefaultConnectorContext (org.apache.rocketmq.connect.runtime.service.DefaultConnectorContext)1 Before (org.junit.Before)1 Test (org.junit.Test)1