Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump logback-core from 1.2.3 to 1.2.9 in /choerodon-starter-nacos-client #43

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions choerodon-gitlab4j-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<modelVersion>4.0.0</modelVersion>
<artifactId>choerodon-gitlab4j-api</artifactId>
<version>2.0.0.RELEASE</version>
<version>2.2.0-19-SNAPSHOT</version>
<packaging>jar</packaging>
<name>choerodon-gitlab4j-api</name>
<description>GitLab API Java Client</description>
Expand All @@ -21,7 +21,7 @@
<parent>
<groupId>io.choerodon</groupId>
<artifactId>choerodon-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<version>2.2.0-19-SNAPSHOT</version>
</parent>
<build>
<defaultGoal>package</defaultGoal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public InputStream getRawBlobContent(Integer projectId, String sha) throws GitLa
*/
public InputStream getRepositoryArchive(Integer projectId, String sha) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("sha", sha);
Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.MEDIA_TYPE_WILDCARD,
Response response = getWithAccepts(Response.Status.OK, formData.asMap(), MediaType.WILDCARD,
"projects", projectId, "repository", "archive");
return (response.readEntity(InputStream.class));
}
Expand Down
5 changes: 2 additions & 3 deletions choerodon-starter-asgard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
<parent>
<artifactId>choerodon-starter-parent</artifactId>
<groupId>io.choerodon</groupId>
<version>2.0.0.RELEASE</version>
<version>2.2.0-19-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>choerodon-starter-asgard</artifactId>
<version>2.0.0.RELEASE</version>

<dependencies>
<dependency>
Expand Down Expand Up @@ -50,4 +49,4 @@
</dependencies>


</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
package io.choerodon.asgard.schedule;


import com.fasterxml.jackson.core.type.TypeReference;

import io.choerodon.asgard.common.AbstractAsgardConsumer;
import io.choerodon.asgard.common.ApplicationContextHelper;
import io.choerodon.asgard.common.UpdateStatusDTO;
import io.choerodon.asgard.schedule.annotation.JobTask;
import io.choerodon.asgard.schedule.dto.PollScheduleInstanceDTO;
import io.choerodon.asgard.schedule.dto.ScheduleInstanceConsumerDTO;
import io.choerodon.asgard.schedule.feign.ScheduleConsumerClient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.util.StringUtils;
import static io.choerodon.asgard.common.InstanceResultUtils.*;

import java.io.IOException;
import java.util.HashMap;
Expand All @@ -26,9 +12,20 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.stream.Collectors;

import static io.choerodon.asgard.common.InstanceResultUtils.getErrorInfoFromException;
import static io.choerodon.asgard.common.InstanceResultUtils.getLoggerException;
import static io.choerodon.asgard.common.InstanceResultUtils.resultToJson;
import com.fasterxml.jackson.core.type.TypeReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.util.StringUtils;

import io.choerodon.asgard.common.AbstractAsgardConsumer;
import io.choerodon.asgard.common.ApplicationContextHelper;
import io.choerodon.asgard.common.UpdateStatusDTO;
import io.choerodon.asgard.schedule.annotation.JobTask;
import io.choerodon.asgard.schedule.dto.PollScheduleInstanceDTO;
import io.choerodon.asgard.schedule.dto.ScheduleInstanceConsumerDTO;
import io.choerodon.asgard.schedule.feign.ScheduleConsumerClient;

public class ScheduleConsumer extends AbstractAsgardConsumer {

Expand Down Expand Up @@ -72,6 +69,17 @@ protected void scheduleRunning(String instance) {
}

private ScheduleInstanceConsumerDTO invoke(final ScheduleInstanceConsumerDTO data) {
final JobTaskInvokeBean invokeBean = invokeBeanMap.get(data.getMethod());
final JobTask jobTask = invokeBean.jobTask;
if (jobTask.enableTransaction()) {
return invokeWithinTransaction(data);
} else {
return invokeWithoutTransaction(data);
}

}

private ScheduleInstanceConsumerDTO invokeWithinTransaction(final ScheduleInstanceConsumerDTO data) {
final JobTaskInvokeBean invokeBean = invokeBeanMap.get(data.getMethod());
final JobTask jobTask = invokeBean.jobTask;
PlatformTransactionManager platformTransactionManager = getSagaTaskTransactionManager(jobTask.transactionManager());
Expand All @@ -97,6 +105,29 @@ private ScheduleInstanceConsumerDTO invoke(final ScheduleInstanceConsumerDTO dat
return data;
}

private ScheduleInstanceConsumerDTO invokeWithoutTransaction(final ScheduleInstanceConsumerDTO data) {
final JobTaskInvokeBean invokeBean = invokeBeanMap.get(data.getMethod());
beforeInvoke(data.getUserDetails());
try {
invokeBean.method.setAccessible(true);
Object result = invokeBean.method.invoke(invokeBean.object, getInputMap(data.getExecuteParams()));
if (result != null) {
result = objectMapper.writeValueAsString(result);
}
scheduleConsumerClient.updateStatus(data.getId(), new UpdateStatusDTO(data.getId(), QuartzDefinition.InstanceStatus.COMPLETED.name(),
resultToJson(result, objectMapper), null, data.getObjectVersionNumber()));
runningTasks.remove(data.getId());
} catch (Exception e) {
String errorMsg = getErrorInfoFromException(e);
LOGGER.info("@JobTask method: {}, id: {} invoke error", data.getMethod(), data.getId(), getLoggerException(e));
invokeError(data, errorMsg);
} finally {
afterInvoke();
}
return data;
}


private void invokeError(final PlatformTransactionManager platformTransactionManager,
final TransactionStatus status,
final ScheduleInstanceConsumerDTO data,
Expand All @@ -106,14 +137,19 @@ private void invokeError(final PlatformTransactionManager platformTransactionMan
} catch (Exception e) {
LOGGER.warn("@JobTask method: {}, id: {} transaction rollback error", data.getMethod(), data.getId(), e);
} finally {
try {
scheduleConsumerClient.updateStatus(data.getId(), new UpdateStatusDTO(data.getId(),
QuartzDefinition.InstanceStatus.FAILED.name(), null, errorMsg, data.getObjectVersionNumber()));
runningTasks.remove(data.getId());
} catch (Exception ex) {
LOGGER.warn("@JobTask method: {}, id: {} updateStatusFailed error, error message: {}", data.getMethod(), data.getId(), ex.getMessage());
runningTasks.remove(data.getId());
}
invokeError(data, errorMsg);
}
}

private void invokeError(final ScheduleInstanceConsumerDTO data,
final String errorMsg) {
try {
scheduleConsumerClient.updateStatus(data.getId(), new UpdateStatusDTO(data.getId(),
QuartzDefinition.InstanceStatus.FAILED.name(), null, errorMsg, data.getObjectVersionNumber()));
runningTasks.remove(data.getId());
} catch (Exception ex) {
LOGGER.warn("@JobTask method: {}, id: {} updateStatusFailed error, error message: {}", data.getMethod(), data.getId(), ex.getMessage());
runningTasks.remove(data.getId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import io.choerodon.core.iam.ResourceLevel;

import org.springframework.transaction.annotation.Isolation;

import io.choerodon.core.iam.ResourceLevel;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface JobTask {
Expand Down Expand Up @@ -41,6 +41,13 @@
*/
boolean transactionReadOnly() default false;

/**
* 是否开启事务
*
* @return 是否开启事务
*/
boolean enableTransaction() default true;

/**
* 事务的隔离级别
*
Expand Down
6 changes: 4 additions & 2 deletions choerodon-starter-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
<parent>
<artifactId>choerodon-starter-parent</artifactId>
<groupId>io.choerodon</groupId>
<version>2.0.0.RELEASE</version>
<version>2.2.0-19-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>choerodon-starter-core</artifactId>

<dependencies>
<!-- 后续升级删除版本号-->
<dependency>
<groupId>org.hzero.starter</groupId>
<artifactId>hzero-starter-mybatis-mapper</artifactId>
<version>1.8.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hzero.boot</groupId>
Expand All @@ -23,4 +25,4 @@
</dependencies>


</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.choerodon.core.utils;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.Arrays;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;

/**
* Copyright (c) 2022. Hand Enterprise Solution Company. All right reserved.
*
* @author [email protected]
* @since 2022/7/13
*/
public class FeignFallbackUtil {

private FeignFallbackUtil() {
}

public static <T> T get(Throwable cause, Class<T> targetClass) {
Assert.notNull(targetClass, "feign target class could not be null!");
Logger logger = LoggerFactory.getLogger(targetClass);
InvocationHandler invocationHandler = (proxy, method, args) -> {
logger.error("error when call {}.{} by params{}", method.getDeclaringClass().getSimpleName(),
method.getName(), JSON.toJSONString(args));
if (cause != null) {
logger.error(cause.getMessage(), cause);
}
return ResponseEntity.badRequest().contentType(MediaType.APPLICATION_JSON).body("请联系运维人员");
};
return (T) Proxy.newProxyInstance(targetClass.getClassLoader(), new Class[]{targetClass}, invocationHandler);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package io.choerodon.core.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Created by younger on 2018/3/29.
*/
public class TypeUtils {

private static final Logger LOGGER = LoggerFactory.getLogger(TypeUtils.class);
public static final String SEARCH_PARAM = "searchParam";
public static final String PARAMS = "params";

private TypeUtils() {
}

/**
* obj转string类型
*/

public static String objToString(Object obj) {
if (obj == null) {
return null;
}
return String.valueOf(obj);
}

/**
* obj转integer类型
*/

public static Integer objToInteger(Object obj) {
if (obj == null || "".equals(obj)) {
return null;
}
return Integer.valueOf(String.valueOf(obj));
}

/**
* obj转long类型
*/

public static Long objToLong(Object obj) {
if (obj == null || "".equals(obj)) {
return null;
}
return Long.valueOf(String.valueOf(obj));
}

/**
* obj转double类型
*/

public static double objTodouble(Object obj) {
if (obj == null || "".equals(obj)) {
return 0;
}
return Double.parseDouble(String.valueOf(obj));
}

/**
* obj转int类型
*/

public static int objToInt(Object obj) {
if (obj == null || "".equals(obj)) {
return 0;
}
return Integer.parseInt(String.valueOf(obj));
}

/**
* obj转boolean类型
*/

public static Boolean objToBoolean(Object obj) {
if (obj == null || "".equals(obj)) {
return false;
}
return Boolean.valueOf(String.valueOf(obj));
}

/**
* 对象转换
*
* @param obj obj
* @param <T> t
* @return t
*/
public static <T> T cast(Object obj) {
if (obj == null) {
return null;
} else {
return (T) obj;
}
}

}
Loading