Skip to content

Commit

Permalink
[INLONG-9337][Manager] Support querying operation records (#9340)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuweng11 authored Nov 28, 2023
1 parent f1395eb commit 7583980
Show file tree
Hide file tree
Showing 40 changed files with 773 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.inlong.manager.client.api.inner.client;

import org.apache.inlong.manager.client.api.ClientConfiguration;
import org.apache.inlong.manager.client.api.service.OperationLogApi;
import org.apache.inlong.manager.client.api.util.ClientUtils;
import org.apache.inlong.manager.pojo.common.PageResult;
import org.apache.inlong.manager.pojo.common.Response;
import org.apache.inlong.manager.pojo.operationLog.OperationLogRequest;
import org.apache.inlong.manager.pojo.operationLog.OperationLogResponse;

public class OperationLogClient {

private final OperationLogApi operationLogApi;

public OperationLogClient(ClientConfiguration configuration) {
operationLogApi = ClientUtils.createRetrofit(configuration).create(OperationLogApi.class);
}

/**
* create us task by sink id
*
* @return task id
*/
public PageResult<OperationLogResponse> list(OperationLogRequest request) {
Response<PageResult<OperationLogResponse>> response =
ClientUtils.executeHttpCall(operationLogApi.list(request));
ClientUtils.assertRespSuccess(response);
if (response.isSuccess()) {
return response.getData();
}
throw new RuntimeException(response.getErrMsg());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.inlong.manager.client.api.service;

import org.apache.inlong.manager.pojo.common.PageResult;
import org.apache.inlong.manager.pojo.common.Response;
import org.apache.inlong.manager.pojo.operationLog.OperationLogRequest;
import org.apache.inlong.manager.pojo.operationLog.OperationLogResponse;

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;

public interface OperationLogApi {

@POST("operationLog/list")
Call<Response<PageResult<OperationLogResponse>>> list(@Body OperationLogRequest request);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.inlong.manager.common.enums;

/**
* Operation target
*/
public enum OperationTarget {

TENANT,

GROUP,

STREAM,

SOURCE,

SINK,

CONSUME,

WORKFLOW,

NODE,

CLUSTER,

TRANSFORM,

INLONG_ROLE,

TENANT_ROLE

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ public class OperationLogEntity implements Serializable {

private static final long serialVersionUID = 1L;
private Integer id;
private String inlongGroupId;
private String inlongStreamId;
private String authenticationType;
private String operationType;
private String operationTarget;
private String httpMethod;
private String invokeMethod;
private String operator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package org.apache.inlong.manager.dao.mapper;

import org.apache.inlong.manager.dao.entity.OperationLogEntity;
import org.apache.inlong.manager.pojo.operationLog.OperationLogRequest;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -36,6 +38,8 @@ public interface OperationLogEntityMapper {

OperationLogEntity selectByPrimaryKey(Integer id);

List<OperationLogEntity> selectByCondition(@Param("request") OperationLogRequest operationLogRequest);

int updateByPrimaryKeySelective(OperationLogEntity record);

int updateByPrimaryKey(OperationLogEntity record);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
<mapper namespace="org.apache.inlong.manager.dao.mapper.OperationLogEntityMapper">
<resultMap id="BaseResultMap" type="org.apache.inlong.manager.dao.entity.OperationLogEntity">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="inlong_group_id" jdbcType="VARCHAR" property="inlongGroupId"/>
<result column="inlong_stream_id" jdbcType="VARCHAR" property="inlongStreamId"/>
<result column="authentication_type" jdbcType="VARCHAR" property="authenticationType"/>
<result column="operation_type" jdbcType="VARCHAR" property="operationType"/>
<result column="operation_target" jdbcType="VARCHAR" property="operationTarget"/>
<result column="http_method" jdbcType="VARCHAR" property="httpMethod"/>
<result column="invoke_method" jdbcType="VARCHAR" property="invokeMethod"/>
<result column="operator" jdbcType="VARCHAR" property="operator"/>
Expand All @@ -38,7 +41,7 @@
<result column="err_msg" jdbcType="LONGVARCHAR" property="errMsg"/>
</resultMap>
<sql id="Base_Column_List">
id, authentication_type, operation_type, http_method, invoke_method, operator,
id, inlong_group_id, inlong_stream_id, authentication_type, operation_type, operation_target, http_method, invoke_method, operator,
proxy, request_url, remote_address, cost_time, status, request_time, body, param, err_msg
</sql>

Expand All @@ -48,25 +51,59 @@
from operation_log
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByCondition" resultMap="BaseResultMap"
parameterType="org.apache.inlong.manager.pojo.operationLog.OperationLogRequest">
select
<include refid="Base_Column_List"/>
from operation_log
<where>
<if test="request.inlongGroupId != null and request.inlongGroupId != ''">
and inlong_group_id = #{request.inlongGroupId, jdbcType=VARCHAR}
</if>
<if test="request.inlongStreamId != null and request.inlongStreamId != ''">
and inlong_stream_id = #{request.inlongStreamId, jdbcType=VARCHAR}
</if>
<if test="request.operationType != null and request.operationType != ''">
and operation_type = #{request.operationType, jdbcType=VARCHAR}
</if>
<if test="request.operationTarget != null and request.operationTarget != ''">
and operation_target = #{request.operationTarget, jdbcType=VARCHAR}
</if>
<if test="request.keyword != null and request.keyword != ''">
and (
inlong_group_id like CONCAT('%', #{request.keyword}, '%')
or inlong_stream_id like CONCAT('%', #{request.keyword}, '%')
)
</if>
<if test="request.startDate != null and request.startDate != '' and request.endDate != null and request.endDate != ''">
and request_time &gt;= #{request.startDate, jdbcType=VARCHAR}
and request_time &lt; #{request.endDate, jdbcType=VARCHAR}
</if>
</where>
order by request_time desc
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete
from operation_log
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="org.apache.inlong.manager.dao.entity.OperationLogEntity">
insert into operation_log (id, authentication_type, operation_type,
insert into operation_log (id, inlong_group_id, inlong_stream_id,
authentication_type, operation_type, operation_target,
http_method, invoke_method, operator,
proxy, request_url, remote_address,
cost_time, status, request_time,
body, param, err_msg)
values (#{id,jdbcType=INTEGER}, #{authenticationType,jdbcType=VARCHAR}, #{operationType,jdbcType=VARCHAR},
values (#{id,jdbcType=INTEGER}, #{inlongGroupId,jdbcType=VARCHAR}, #{inlongStreamId,jdbcType=VARCHAR},
#{authenticationType,jdbcType=VARCHAR}, #{operationType,jdbcType=VARCHAR}, #{operationTarget,jdbcType=VARCHAR},
#{httpMethod,jdbcType=VARCHAR}, #{invokeMethod,jdbcType=VARCHAR}, #{operator,jdbcType=VARCHAR},
#{proxy,jdbcType=VARCHAR}, #{requestUrl,jdbcType=VARCHAR}, #{remoteAddress,jdbcType=VARCHAR},
#{costTime,jdbcType=BIGINT}, #{status,jdbcType=TINYINT}, #{requestTime,jdbcType=TIMESTAMP},
#{body,jdbcType=LONGVARCHAR}, #{param,jdbcType=LONGVARCHAR}, #{errMsg,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertBatch">
insert into operation_log (id, authentication_type, operation_type,
insert into operation_log (id, inlong_group_id, inlong_stream_id,
authentication_type, operation_type, operation_target,
http_method, invoke_method, operator,
proxy, request_url, remote_address,
cost_time, status, request_time,
Expand All @@ -75,8 +112,9 @@
VALUES
<foreach collection="list" item="log" separator=",">
(
#{log.id,jdbcType=INTEGER}, #{log.authenticationType,jdbcType=VARCHAR},
#{log.operationType,jdbcType=VARCHAR},
#{log.id,jdbcType=INTEGER}, #{log.inlongGroupId,jdbcType=VARCHAR},
#{log.inlongStreamId,jdbcType=VARCHAR}, #{log.authenticationType,jdbcType=VARCHAR},
#{log.operationType,jdbcType=VARCHAR}, #{log.operationTarget,jdbcType=VARCHAR},
#{log.httpMethod,jdbcType=VARCHAR}, #{log.invokeMethod,jdbcType=VARCHAR},
#{log.operator,jdbcType=VARCHAR},
#{log.proxy,jdbcType=VARCHAR}, #{log.requestUrl,jdbcType=VARCHAR},
Expand All @@ -95,12 +133,21 @@
<if test="id != null">
id,
</if>
<if test="inlongGroupId != null">
inlong_group_id,
</if>
<if test="inlongStreamId != null">
inlong_stream_id,
</if>
<if test="authenticationType != null">
authentication_type,
</if>
<if test="operationType != null">
operation_type,
</if>
<if test="operationTarget != null">
operation_target,
</if>
<if test="httpMethod != null">
http_method,
</if>
Expand Down Expand Up @@ -142,12 +189,21 @@
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="inlongGroupId != null">
#{inlongGroupId,jdbcType=VARCHAR},
</if>
<if test="inlongStreamId != null">
#{inlongStreamId,jdbcType=VARCHAR},
</if>
<if test="authenticationType != null">
#{authenticationType,jdbcType=VARCHAR},
</if>
<if test="operationType != null">
#{operationType,jdbcType=VARCHAR},
</if>
<if test="operationTarget != null">
#{operationTarget,jdbcType=VARCHAR},
</if>
<if test="httpMethod != null">
#{httpMethod,jdbcType=VARCHAR},
</if>
Expand Down Expand Up @@ -190,12 +246,21 @@
parameterType="org.apache.inlong.manager.dao.entity.OperationLogEntity">
update operation_log
<set>
<if test="inlongGroupId != null">
inlong_group_id = #{inlongGroupId,jdbcType=VARCHAR},
</if>
<if test="inlongStreamId != null">
inlong_stream_id = #{inlongStreamId,jdbcType=VARCHAR},
</if>
<if test="authenticationType != null">
authentication_type = #{authenticationType,jdbcType=VARCHAR},
</if>
<if test="operationType != null">
operation_type = #{operationType,jdbcType=VARCHAR},
</if>
<if test="operationTarget != null">
operation_target = #{operationTarget,jdbcType=VARCHAR},
</if>
<if test="httpMethod != null">
http_method = #{httpMethod,jdbcType=VARCHAR},
</if>
Expand Down Expand Up @@ -238,8 +303,11 @@
<update id="updateByPrimaryKey"
parameterType="org.apache.inlong.manager.dao.entity.OperationLogEntity">
update operation_log
set authentication_type = #{authenticationType,jdbcType=VARCHAR},
set inlong_group_id = #{inlongGroupId,jdbcType=VARCHAR},
inlong_stream_id = #{inlongStreamId,jdbcType=VARCHAR},
authentication_type = #{authenticationType,jdbcType=VARCHAR},
operation_type = #{operationType,jdbcType=VARCHAR},
operation_target = #{operationTarget,jdbcType=VARCHAR},
http_method = #{httpMethod,jdbcType=VARCHAR},
invoke_method = #{invokeMethod,jdbcType=VARCHAR},
operator = #{operator,jdbcType=VARCHAR},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.inlong.manager.pojo.operationLog;

import org.apache.inlong.manager.pojo.common.PageRequest;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* Request of get operation records
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OperationLogRequest extends PageRequest {

@ApiModelProperty("Inlong group id")
private String inlongGroupId;

@ApiModelProperty("Inlong stream id")
private String inlongStreamId;

@ApiModelProperty("Operation type")
private String operationType;

@ApiModelProperty("Operation target")
private String operationTarget;

@ApiModelProperty(value = "keyword")
private String keyword;

@ApiModelProperty(value = "query start date, format by 'yyyy-MM-dd'", required = false, example = "2022-01-01")
private String startDate;

@ApiModelProperty(value = "query end date, format by 'yyyy-MM-dd'", required = false, example = "2022-01-01")
private String endDate;

}
Loading

0 comments on commit 7583980

Please sign in to comment.