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;
}
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());
}
}
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);
}
}
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;
}
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;
}
Aggregations