com.aliyun.openservices.log.common.Consts Java Examples

The following examples show how to use com.aliyun.openservices.log.common.Consts. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SlsClientProvider.java    From alibaba-flink-connectors with Apache License 2.0 5 votes vote down vote up
public SlsClientProvider(
		String endPoint,
		String accessKeyId,
		String accessKeySecret,
		String consumerGroup,
		boolean directMode) {
	super(accessKeyId, accessKeySecret);
	this.endPoint = endPoint;
	this.consumerGroup = consumerGroup;
	this.directMode = directMode;
	Consts.HTTP_SEND_TIME_OUT = 10 * 1000;
}
 
Example #2
Source File: SlsClientProvider.java    From alibaba-flink-connectors with Apache License 2.0 5 votes vote down vote up
public SlsClientProvider(
		String endPoint,
		Configuration properties,
		String consumerGroup,
		boolean directMode) {
	super(properties);
	this.endPoint = endPoint;
	this.heartBeatIntervalMillis = heartBeatIntervalMillis;
	this.consumerGroup = consumerGroup;
	this.directMode = directMode;
	Consts.HTTP_SEND_TIME_OUT = 10 * 1000;
}
 
Example #3
Source File: SlsRecordReader.java    From alibaba-flink-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public void seek(String s) throws IOException {
	// 0 means the start of
	if (s.equalsIgnoreCase(SlsSourceFunction.NEW_SLS_START_FLAG)) {
		try {
			this.nextBeginCursor = RetryUtils.executeWithRetry(
					() -> getSlsClientProvider().getClient().GetCursor(project, logStore, shardId, Consts.CursorMode.BEGIN).GetCursor(),
					maxRetryTime, 10000, false);
		} catch (Exception e){
			throw ErrorUtils.getException(e.getMessage());
		}
	} else {
		this.nextBeginCursor = s;
	}
}
 
Example #4
Source File: IOThread.java    From aliyun-log-producer-java with Apache License 2.0 5 votes vote down vote up
private PutLogsResponse sendRequest(Client clt, BlockedData bd) throws LogException {
    PutLogsRequest request = buildRequest(bd);
    List<TagContent> tags = new ArrayList<TagContent>();
    tags.add(new TagContent("__pack_id__", bd.data.getPackageId()));
    request.SetTags(tags);
    request.setContentType(producerConfig.logsFormat.equals("protobuf") ?
            Consts.CONST_PROTO_BUF
            : Consts.CONST_SLS_JSON);
    PutLogsResponse response = clt.PutLogs(request);
    long tmpBytes = sendLogBytes.get();
    sendLogBytes.set(tmpBytes + bd.bytes);
    return response;
}
 
Example #5
Source File: PackageData.java    From aliyun-log-producer-java with Apache License 2.0 5 votes vote down vote up
static String GetLocalMachineIp() {
    InetAddressValidator validator = new InetAddressValidator();
    String candidate = "";
    try {
        for (Enumeration<NetworkInterface> ifaces = NetworkInterface
                .getNetworkInterfaces(); ifaces.hasMoreElements(); ) {
            NetworkInterface iface = ifaces.nextElement();

            if (iface.isUp()) {
                for (Enumeration<InetAddress> addresses = iface
                        .getInetAddresses(); addresses.hasMoreElements(); ) {

                    InetAddress address = addresses.nextElement();

                    if (!address.isLinkLocalAddress() && address.getHostAddress() != null) {
                        String ipAddress = address.getHostAddress();
                        if (ipAddress.equals(Consts.CONST_LOCAL_IP)) {
                            continue;
                        }
                        if (validator.isValidInet4Address(ipAddress)) {
                            return ipAddress;
                        }
                        if (validator.isValid(ipAddress)) {
                            candidate = ipAddress;
                        }
                    }
                }
            }
        }
    } catch (SocketException e) {
        LOGGER.error("Failed to get local machine IP.", e);
    }
    return candidate;
}
 
Example #6
Source File: SlsRecordReader.java    From alibaba-flink-connectors with Apache License 2.0 4 votes vote down vote up
@Override
public void open(
		InputSplit split, RuntimeContext context) throws IOException {
	SlsInputSplit slsInputSplit = (SlsInputSplit) split;
	LOG.info(String.format("open project[%s] logStore[%s],consumer[%s]-%s  startTime[%d)", project, logStore,
						accessKeyId,
						slsInputSplit.toString(), startInSec));

	int curRetry = 0;
	while (curRetry++ < maxRetryTime) {
		try {
			List<Shard> shardsList  = getShardsList();
			if (initPartitionCount != shardsList.size()){
				ErrorUtils.throwException(
						String.format("Source {%s} partitions number has changed from {%s} to {%s} \n " +
										"Wait the failover finish, blink is trying to recovery from " +
										"source partition change", getReaderName(),
								String.valueOf(initPartitionCount), String.valueOf(getPartitionsNums())));
			}
			this.shardId = split.getSplitNumber();
			for (Shard shard: shardsList) {
				if (shard.GetShardId() == this.shardId){
					this.shard = shard;
					break;
				}
			}
			if (shard.getStatus().equalsIgnoreCase("readonly")) {
				LOG.info("ShardId " + shard.GetShardId() + " status:readOnly");
				isReadOnlyShard = true;
				this.endCursor = getSlsClientProvider().getClient().GetCursor(project, logStore, shardId, Consts
						.CursorMode.END).GetCursor();
			} else {
				LOG.info("ShardId " + shard.GetShardId() + " status:readwrite");
				isReadOnlyShard = false;
			}
			this.nextBeginCursor = getSlsClientProvider().getClient()
														.GetCursor(project, logStore, shardId, startInSec)
														.GetCursor();
			if (stopInSec == Integer.MAX_VALUE) {
				this.stopCursor = null;

			} else {
				this.stopCursor = getSlsClientProvider().getClient()
						.GetCursor(project, logStore, shardId, stopInSec).GetCursor();
			}

			if (consumerGroup == null) {
				LOG.info(String.format(
						"Open method get init cursor, " +
						"project[%s]-logStore[%s]-shardId[%d]-startInSec[%d]-Cursor[%s]",
						project,
						logStore,
						shardId,
						startInSec,
						nextBeginCursor));
			} else {
				LOG.info(String.format(
						"Open method get init cursor, " +
						"project[%s]-logStore[%s]-shardId[%d]-startInSec[%d]-Cursor[%s]-ConsumerGroup[%s]",
						project,
						logStore,
						shardId,
						startInSec,
						nextBeginCursor,
						consumerGroup));
			}
			break;
		} catch (LogException e) {
			LOG.error("Error in get shard list", e);
			// refresh sts account
			getSlsClientProvider().getClient(true, true);
			if (curRetry == maxRetryTime) {
				ErrorUtils.throwException(
						e.getMessage());
			}
			try {
				Thread.sleep(curRetry * 500);
			} catch (Exception e1) {

			}
		}
	}
	initPartitionNumsListener();
}
 
Example #7
Source File: PackageManager.java    From aliyun-log-producer-java with Apache License 2.0 4 votes vote down vote up
void acquireBytes(final int b) {
    if (b > config.memPoolSizeInByte || b > Consts.CONST_MAX_PUT_SIZE) {
        throw new RuntimeException("Failed to acquire bytes " + b + ", which cannot exceed memPoolSizeInByte " + config.memPoolSizeInByte + " and CONST_MAX_PUT_SIZE " + Consts.CONST_MAX_PUT_SIZE);
    }
    semaphore.acquireUninterruptibly(b);
}
 
Example #8
Source File: PackageManager.java    From aliyun-log-producer-java with Apache License 2.0 4 votes vote down vote up
boolean tryAcquireBytes(final int b) {
    if (b > config.memPoolSizeInByte || b > Consts.CONST_MAX_PUT_SIZE) {
        return false;
    }
    return semaphore.tryAcquire(b);
}