use of org.apache.inlong.manager.common.pojo.source.SourceRequest in project incubator-inlong by apache.
the class InnerInlongManagerClient method updateSource.
public Pair<Boolean, String> updateSource(SourceRequest sourceRequest) {
final String path = HTTP_PATH + "/source/update";
final String url = formatUrl(path);
final String storage = GsonUtil.toJson(sourceRequest);
final RequestBody storageBody = RequestBody.create(MediaType.parse("application/json"), storage);
Request request = new Request.Builder().method("POST", storageBody).url(url).build();
Call call = httpClient.newCall(request);
try {
Response response = call.execute();
String body = response.body().string();
AssertUtil.isTrue(response.isSuccessful(), String.format("Inlong request failed:%s", body));
org.apache.inlong.manager.common.beans.Response responseBody = InlongParser.parseResponse(body);
if (responseBody.getData() != null) {
return Pair.of(Boolean.valueOf(responseBody.getData().toString()), responseBody.getErrMsg());
} else {
return Pair.of(false, responseBody.getErrMsg());
}
} catch (Exception e) {
throw new RuntimeException(String.format("Inlong source update failed with ex:%s", e.getMessage()), e);
}
}
use of org.apache.inlong.manager.common.pojo.source.SourceRequest in project incubator-inlong by apache.
the class StreamSourceServiceImpl method restart.
@Override
public boolean restart(Integer id, String sourceType, String operator) {
LOGGER.info("begin to restart source by id={}, sourceType={}", id, sourceType);
Preconditions.checkNotNull(id, Constant.ID_IS_EMPTY);
StreamSourceEntity entity = sourceMapper.selectByPrimaryKey(id);
Preconditions.checkNotNull(entity, ErrorCodeEnum.SOURCE_INFO_NOT_FOUND.getMessage());
commonOperateService.checkGroupStatus(entity.getInlongGroupId(), operator);
StreamSourceOperation operation = operationFactory.getInstance(SourceType.forType(sourceType));
SourceRequest sourceRequest = new SourceRequest();
CommonBeanUtils.copyProperties(entity, sourceRequest, true);
operation.restartOpt(sourceRequest, operator);
LOGGER.info("success to restart source info:{}", entity);
return true;
}
use of org.apache.inlong.manager.common.pojo.source.SourceRequest in project incubator-inlong by apache.
the class DefaultInlongStreamBuilder method source.
@Override
public InlongStreamBuilder source(StreamSource source) {
inlongStream.addSource(source);
SourceRequest sourceRequest = InlongStreamSourceTransfer.createSourceRequest(source, streamContext.getStreamInfo());
streamContext.setSourceRequest(sourceRequest);
return this;
}
use of org.apache.inlong.manager.common.pojo.source.SourceRequest in project incubator-inlong by apache.
the class DefaultInlongStreamBuilder method initOrUpdate.
@Override
public InlongStream initOrUpdate() {
InlongStreamInfo dataStreamInfo = streamContext.getStreamInfo();
Pair<Boolean, InlongStreamInfo> existMsg = managerClient.isStreamExists(dataStreamInfo);
if (existMsg.getKey()) {
Pair<Boolean, String> updateMsg = managerClient.updateStreamInfo(dataStreamInfo);
if (updateMsg.getKey()) {
List<SourceRequest> sourceRequests = Lists.newArrayList(streamContext.getSourceRequests().values());
for (SourceRequest sourceRequest : sourceRequests) {
sourceRequest.setId(initOrUpdateSource(sourceRequest));
}
List<SinkRequest> sinkRequests = Lists.newArrayList(streamContext.getSinkRequests().values());
for (SinkRequest sinkRequest : sinkRequests) {
sinkRequest.setId(initOrUpdateSink(sinkRequest));
}
} else {
throw new RuntimeException(String.format("Update data stream failed:%s", updateMsg.getValue()));
}
return inlongStream;
} else {
return init();
}
}
use of org.apache.inlong.manager.common.pojo.source.SourceRequest in project incubator-inlong by apache.
the class DefaultInlongStreamBuilder method init.
@Override
public InlongStream init() {
InlongStreamInfo streamInfo = streamContext.getStreamInfo();
String streamIndex = managerClient.createStreamInfo(streamInfo);
streamInfo.setId(Double.valueOf(streamIndex).intValue());
// Create source and update index
List<SourceRequest> sourceRequests = Lists.newArrayList(streamContext.getSourceRequests().values());
for (SourceRequest sourceRequest : sourceRequests) {
String sourceIndex = managerClient.createSource(sourceRequest);
sourceRequest.setId(Double.valueOf(sourceIndex).intValue());
}
// Create sink and update index
List<SinkRequest> sinkRequests = Lists.newArrayList(streamContext.getSinkRequests().values());
for (SinkRequest sinkRequest : sinkRequests) {
String sinkIndex = managerClient.createSink(sinkRequest);
sinkRequest.setId(Double.valueOf(sinkIndex).intValue());
}
return inlongStream;
}
Aggregations