Search in sources :

Example 1 with NetworkAddress

use of org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress in project incubator-skywalking by apache.

the class NetworkAddressIDService method getOrCreate.

@Override
public int getOrCreate(String networkAddress) {
    int addressId = getNetworkAddressCacheService().getAddressId(networkAddress);
    if (addressId != 0) {
        int applicationId = getApplicationIDService().getOrCreateForAddressId(addressId, networkAddress);
        if (applicationId != 0) {
            int instanceId = getInstanceIDService().getOrCreateByAddressId(applicationId, addressId, System.currentTimeMillis());
            if (instanceId != 0) {
                return addressId;
            }
        }
    } else {
        NetworkAddress newNetworkAddress = new NetworkAddress();
        newNetworkAddress.setId(String.valueOf(Const.NONE));
        newNetworkAddress.setNetworkAddress(networkAddress);
        newNetworkAddress.setSpanLayer(Const.NONE);
        newNetworkAddress.setServerType(Const.NONE);
        newNetworkAddress.setAddressId(Const.NONE);
        getNetworkAddressGraph().start(newNetworkAddress);
    }
    return 0;
}
Also used : NetworkAddress(org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress)

Example 2 with NetworkAddress

use of org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress in project incubator-skywalking by apache.

the class NetworkAddressRegisterSerialWorker method onWork.

@Override
protected void onWork(NetworkAddress networkAddress) throws WorkerException {
    logger.debug("register network address, address: {}", networkAddress.getNetworkAddress());
    if (networkAddress.getAddressId() == 0) {
        int addressId = networkAddressCacheService.getAddressId(networkAddress.getNetworkAddress());
        if (addressId == 0) {
            NetworkAddress newNetworkAddress;
            int min = networkAddressRegisterDAO.getMinNetworkAddressId();
            if (min == 0) {
                newNetworkAddress = new NetworkAddress();
                newNetworkAddress.setId("-1");
                newNetworkAddress.setAddressId(-1);
                newNetworkAddress.setSpanLayer(networkAddress.getSpanLayer());
                newNetworkAddress.setNetworkAddress(networkAddress.getNetworkAddress());
            } else {
                int max = networkAddressRegisterDAO.getMaxNetworkAddressId();
                addressId = IdAutoIncrement.INSTANCE.increment(min, max);
                newNetworkAddress = new NetworkAddress();
                newNetworkAddress.setId(String.valueOf(addressId));
                newNetworkAddress.setAddressId(addressId);
                newNetworkAddress.setSpanLayer(networkAddress.getSpanLayer());
                newNetworkAddress.setNetworkAddress(networkAddress.getNetworkAddress());
            }
            networkAddressRegisterDAO.save(newNetworkAddress);
        }
    } else {
        networkAddressRegisterDAO.update(networkAddress.getId(), networkAddress.getSpanLayer(), networkAddress.getServerType());
    }
}
Also used : NetworkAddress(org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress)

Example 3 with NetworkAddress

use of org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress in project incubator-skywalking by apache.

the class NetworkAddressIDService method update.

@Override
public void update(int addressId, int spanLayer, int serverType) {
    if (!networkAddressCacheService.compare(addressId, spanLayer, serverType)) {
        NetworkAddress newNetworkAddress = new NetworkAddress();
        newNetworkAddress.setId(String.valueOf(addressId));
        newNetworkAddress.setSpanLayer(spanLayer);
        newNetworkAddress.setServerType(serverType);
        newNetworkAddress.setAddressId(addressId);
        getNetworkAddressGraph().start(newNetworkAddress);
    }
}
Also used : NetworkAddress(org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress)

Example 4 with NetworkAddress

use of org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress in project incubator-skywalking by apache.

the class NetworkAddressEsCacheDAO method getAddress.

@Override
public NetworkAddress getAddress(int addressId) {
    ElasticSearchClient client = getClient();
    GetRequestBuilder getRequestBuilder = client.prepareGet(NetworkAddressTable.TABLE, String.valueOf(addressId));
    GetResponse getResponse = getRequestBuilder.get();
    if (getResponse.isExists()) {
        NetworkAddress address = new NetworkAddress();
        address.setId((String) getResponse.getSource().get(NetworkAddressTable.COLUMN_ID));
        address.setAddressId(((Number) getResponse.getSource().get(NetworkAddressTable.COLUMN_ADDRESS_ID)).intValue());
        address.setSpanLayer(((Number) getResponse.getSource().get(NetworkAddressTable.COLUMN_SPAN_LAYER)).intValue());
        address.setServerType(((Number) getResponse.getSource().get(NetworkAddressTable.COLUMN_SERVER_TYPE)).intValue());
        address.setNetworkAddress((String) getResponse.getSource().get(NetworkAddressTable.COLUMN_NETWORK_ADDRESS));
        return address;
    }
    return null;
}
Also used : NetworkAddress(org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) GetResponse(org.elasticsearch.action.get.GetResponse) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder)

Example 5 with NetworkAddress

use of org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress in project incubator-skywalking by apache.

the class NetworkAddressH2CacheDAO method getAddress.

@Override
public NetworkAddress getAddress(int addressId) {
    logger.debug("get network address, address id: {}", addressId);
    H2Client client = getClient();
    String dynamicSql = "select * from {0} where {1} = ?";
    String sql = SqlBuilder.buildSql(dynamicSql, NetworkAddressTable.TABLE, NetworkAddressTable.COLUMN_ADDRESS_ID);
    Object[] params = new Object[] { addressId };
    try (ResultSet rs = client.executeQuery(sql, params)) {
        if (rs.next()) {
            NetworkAddress networkAddress = new NetworkAddress();
            networkAddress.setId(rs.getString(NetworkAddressTable.COLUMN_ID));
            networkAddress.setAddressId(rs.getInt(NetworkAddressTable.COLUMN_ADDRESS_ID));
            networkAddress.setNetworkAddress(rs.getString(NetworkAddressTable.COLUMN_NETWORK_ADDRESS));
            networkAddress.setSpanLayer(rs.getInt(NetworkAddressTable.COLUMN_SPAN_LAYER));
            networkAddress.setServerType(rs.getInt(NetworkAddressTable.COLUMN_SERVER_TYPE));
            return networkAddress;
        }
    } catch (SQLException | H2ClientException e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}
Also used : H2Client(org.apache.skywalking.apm.collector.client.h2.H2Client) NetworkAddress(org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) H2ClientException(org.apache.skywalking.apm.collector.client.h2.H2ClientException)

Aggregations

NetworkAddress (org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress)5 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ElasticSearchClient (org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)1 H2Client (org.apache.skywalking.apm.collector.client.h2.H2Client)1 H2ClientException (org.apache.skywalking.apm.collector.client.h2.H2ClientException)1 GetRequestBuilder (org.elasticsearch.action.get.GetRequestBuilder)1 GetResponse (org.elasticsearch.action.get.GetResponse)1