Skip to content

Commit

Permalink
for sonarqube
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Apr 6, 2017
1 parent 23ddd21 commit ac34ca6
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,5 @@ public void write(final JsonWriter out, final CloudAppConfiguration value) throw
out.name("eventTraceSamplingCount").value(value.getEventTraceSamplingCount());
out.endObject();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ public static final class CloudJobConfigurationGsonTypeAdapter extends AbstractJ
protected void addToCustomizedValueMap(final String jsonName, final JsonReader in, final Map<String, Object> customizedValueMap) throws IOException {
switch (jsonName) {
case "appName":
customizedValueMap.put("appName", in.nextString());
customizedValueMap.put(jsonName, in.nextString());
break;
case "cpuCount":
customizedValueMap.put("cpuCount", in.nextDouble());
customizedValueMap.put(jsonName, in.nextDouble());
break;
case "memoryMB":
customizedValueMap.put("memoryMB", in.nextDouble());
customizedValueMap.put(jsonName, in.nextDouble());
break;
case "jobExecutionType":
customizedValueMap.put("jobExecutionType", in.nextString());
customizedValueMap.put(jsonName, in.nextString());
break;
case "beanName":
customizedValueMap.put("beanName", in.nextString());
customizedValueMap.put(jsonName, in.nextString());
break;
case "applicationContext":
customizedValueMap.put("applicationContext", in.nextString());
customizedValueMap.put(jsonName, in.nextString());
break;
default:
in.skipValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public final class MesosConfiguration {
public static final String FRAMEWORK_NAME = "Elastic-Job-Cloud";

/**
* 框架Failover超时时间,默认为1周.
* 框架失效转移超时秒数. 默认为1周
*/
public static final double FRAMEWORK_FAILOVER_TIMEOUT = 60 * 60 * 24 * 7;
public static final double FRAMEWORK_FAILOVER_TIMEOUT_SECONDS = 60 * 60 * 24 * 7D;

private final String user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.apache.mesos.Protos;
import org.apache.mesos.SchedulerDriver;

import static com.dangdang.ddframe.job.cloud.scheduler.env.MesosConfiguration.FRAMEWORK_FAILOVER_TIMEOUT;
import static com.dangdang.ddframe.job.cloud.scheduler.env.MesosConfiguration.FRAMEWORK_FAILOVER_TIMEOUT_SECONDS;
import static com.dangdang.ddframe.job.cloud.scheduler.env.MesosConfiguration.FRAMEWORK_NAME;

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ private SchedulerDriver getSchedulerDriver(final TaskScheduler taskScheduler, fi
builder.setId(Protos.FrameworkID.newBuilder().setValue(frameworkIDOptional.get()).build());
}
Protos.FrameworkInfo frameworkInfo = builder.setUser(mesosConfig.getUser()).setName(FRAMEWORK_NAME)
.setHostname(mesosConfig.getHostname()).setFailoverTimeout(FRAMEWORK_FAILOVER_TIMEOUT)
.setHostname(mesosConfig.getHostname()).setFailoverTimeout(FRAMEWORK_FAILOVER_TIMEOUT_SECONDS)
.setWebuiUrl(WEB_UI_PROTOCOL + env.getFrameworkHostPort()).build();
return new MesosSchedulerDriver(new SchedulerEngine(taskScheduler, facadeService, jobEventBus, frameworkIDService, statisticManager), frameworkInfo, mesosConfig.getUrl());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class CloudOperationRestfulApi {

private static ProducerManager producerManager;

private static final long RECONCILE_INTERVAL = 10 * 1000;
private static final long RECONCILE_MILLIS_INTERVAL = 10 * 1000L;

private static long lastReconcileTime;

Expand Down Expand Up @@ -80,7 +80,7 @@ public void implicitReconcile() {
}

private void validReconcileInterval() {
if (System.currentTimeMillis() < lastReconcileTime + RECONCILE_INTERVAL) {
if (System.currentTimeMillis() < lastReconcileTime + RECONCILE_MILLIS_INTERVAL) {
throw new RuntimeException("Repeat explicitReconcile");
}
lastReconcileTime = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.quartz.plugins.management.ShutdownHookPlugin;
import org.quartz.simpl.SimpleThreadPool;

import java.util.Map;
import java.util.Properties;

/**
Expand Down Expand Up @@ -82,10 +81,7 @@ void start() {
void register(final StatisticJob statisticJob) {
try {
JobDetail jobDetail = statisticJob.buildJobDetail();
Map<String, Object> dataMap = statisticJob.getDataMap();
for (String each : dataMap.keySet()) {
jobDetail.getJobDataMap().put(each, dataMap.get(each));
}
jobDetail.getJobDataMap().putAll(statisticJob.getDataMap());
scheduler.scheduleJob(jobDetail, statisticJob.buildTrigger());
} catch (final SchedulerException ex) {
throw new JobStatisticException(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,20 @@ private void statisticTask(final int runningCount) {
repository.add(taskRunningStatistics);
}

private int getJobRunningCount(final Map<String, Set<TaskContext>> allRunnintTasks) {
private int getJobRunningCount(final Map<String, Set<TaskContext>> allRunningTasks) {
int result = 0;
for (String each : allRunnintTasks.keySet()) {
if (!allRunnintTasks.get(each).isEmpty()) {
for (Map.Entry<String, Set<TaskContext>> entry : allRunningTasks.entrySet()) {
if (!entry.getValue().isEmpty()) {
result++;
}
}
return result;
}

private int getTaskRunningCount(final Map<String, Set<TaskContext>> allRunnintTasks) {
private int getTaskRunningCount(final Map<String, Set<TaskContext>> allRunningTasks) {
int result = 0;
for (String each : allRunnintTasks.keySet()) {
result += allRunnintTasks.get(each).size();
for (Map.Entry<String, Set<TaskContext>> entry : allRunningTasks.entrySet()) {
result += entry.getValue().size();
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ private String buildWhere(final String tableName, final Collection<String> table
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append(" WHERE 1=1");
if (null != condition.getFields() && !condition.getFields().isEmpty()) {
for (String each : condition.getFields().keySet()) {
String lowerUnderscore = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, each);
if (null != condition.getFields().get(each) && tableFields.contains(lowerUnderscore)) {
for (Map.Entry<String, Object> entry : condition.getFields().entrySet()) {
String lowerUnderscore = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getKey());
if (null != entry.getValue() && tableFields.contains(lowerUnderscore)) {
sqlBuilder.append(" AND ").append(lowerUnderscore).append("=?");
}
}
Expand All @@ -212,12 +212,20 @@ private String buildWhere(final String tableName, final Collection<String> table
private void setBindValue(final PreparedStatement preparedStatement, final Collection<String> tableFields, final Condition condition) throws SQLException {
int index = 1;
if (null != condition.getFields() && !condition.getFields().isEmpty()) {
for (String each : condition.getFields().keySet()) {
String lowerUnderscore = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, each);
if (null != condition.getFields().get(each) && tableFields.contains(lowerUnderscore)) {
preparedStatement.setString(index++, String.valueOf(condition.getFields().get(each)));
for (Map.Entry<String, Object> entry : condition.getFields().entrySet()) {
String lowerUnderscore = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getKey());
if (null != entry.getValue() && tableFields.contains(lowerUnderscore)) {
preparedStatement.setString(index++, String.valueOf(entry.getValue()));
}
}


// for (String each : condition.getFields().keySet()) {
// String lowerUnderscore = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, each);
// if (null != condition.getFields().get(each) && tableFields.contains(lowerUnderscore)) {
// preparedStatement.setString(index++, String.valueOf(condition.getFields().get(each)));
// }
// }
}
if (null != condition.getStartTime()) {
preparedStatement.setTimestamp(index++, new Timestamp(condition.getStartTime().getTime()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;

import java.util.EnumMap;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -37,7 +38,7 @@
@NoArgsConstructor
public final class JobProperties {

private Map<JobPropertiesEnum, String> map = new LinkedHashMap<>(JobPropertiesEnum.values().length, 1);
private EnumMap<JobPropertiesEnum, String> map = new EnumMap<>(JobPropertiesEnum.class);

/**
* 设置作业属性.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class RegExceptionHandler {
* @param cause 待处理异常.
*/
public static void handleException(final Exception cause) {
if (isIgnoredException(cause) || isIgnoredException(cause.getCause())) {
if (isIgnoredException(cause) || null != cause.getCause() && isIgnoredException(cause.getCause())) {
log.debug("Elastic job: ignored exception for: {}", cause.getMessage());
} else if (cause instanceof InterruptedException) {
Thread.currentThread().interrupt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,19 @@ private JobCoreConfiguration getJobCoreConfiguration(final String jobName, final

private JobTypeConfiguration getJobTypeConfiguration(
final JobCoreConfiguration coreConfig, final JobType jobType, final String jobClass, final boolean streamingProcess, final String scriptCommandLine) {
JobTypeConfiguration result;
Preconditions.checkNotNull(jobType, "jobType cannot be null.");
switch (jobType) {
case SIMPLE:
Preconditions.checkArgument(!Strings.isNullOrEmpty(jobClass), "jobClass cannot be empty.");
result = new SimpleJobConfiguration(coreConfig, jobClass);
break;
return new SimpleJobConfiguration(coreConfig, jobClass);
case DATAFLOW:
Preconditions.checkArgument(!Strings.isNullOrEmpty(jobClass), "jobClass cannot be empty.");
result = new DataflowJobConfiguration(coreConfig, jobClass, streamingProcess);
break;
return new DataflowJobConfiguration(coreConfig, jobClass, streamingProcess);
case SCRIPT:
result = new ScriptJobConfiguration(coreConfig, scriptCommandLine);
break;
return new ScriptJobConfiguration(coreConfig, scriptCommandLine);
default:
throw new UnsupportedOperationException(jobType.name());
}
return result;
}

protected abstract T getJobRootConfiguration(final JobTypeConfiguration typeConfig, final Map<String, Object> customizedValueMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void checkMaxTimeDiffSecondsTolerable() throws JobExecutionEnvironmentExc
long timeDiff = Math.abs(timeService.getCurrentMillis() - jobNodeStorage.getRegistryCenterTime());
if (timeDiff > maxTimeDiffSeconds * 1000L) {
throw new JobExecutionEnvironmentException(
"Time different between job server and register center exceed '%s' seconds, max time different is '%s' seconds.", Long.valueOf(timeDiff / 1000).intValue(), maxTimeDiffSeconds);
"Time different between job server and register center exceed '%s' seconds, max time different is '%s' seconds.", timeDiff / 1000, maxTimeDiffSeconds);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,25 @@ static final class LiteJobConfigurationGsonTypeAdapter extends AbstractJobConfig
protected void addToCustomizedValueMap(final String jsonName, final JsonReader in, final Map<String, Object> customizedValueMap) throws IOException {
switch (jsonName) {
case "monitorExecution":
customizedValueMap.put("monitorExecution", in.nextBoolean());
customizedValueMap.put(jsonName, in.nextBoolean());
break;
case "maxTimeDiffSeconds":
customizedValueMap.put("maxTimeDiffSeconds", in.nextInt());
customizedValueMap.put(jsonName, in.nextInt());
break;
case "monitorPort":
customizedValueMap.put("monitorPort", in.nextInt());
customizedValueMap.put(jsonName, in.nextInt());
break;
case "jobShardingStrategyClass":
customizedValueMap.put("jobShardingStrategyClass", in.nextString());
customizedValueMap.put(jsonName, in.nextString());
break;
case "reconcileIntervalMinutes":
customizedValueMap.put("reconcileIntervalMinutes", in.nextInt());
customizedValueMap.put(jsonName, in.nextInt());
break;
case "disabled":
customizedValueMap.put("disabled", in.nextBoolean());
customizedValueMap.put(jsonName, in.nextBoolean());
break;
case "overwrite":
customizedValueMap.put("overwrite", in.nextBoolean());
customizedValueMap.put(jsonName, in.nextBoolean());
break;
default:
in.skipValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
*
* @author caohao
*/
@RequiredArgsConstructor
@Getter
@Setter
@RequiredArgsConstructor
public final class ServerBriefInfo implements Serializable, Comparable<ServerBriefInfo> {

private static final long serialVersionUID = 1133149706443681483L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;

import java.util.LinkedHashMap;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.CLASS_ATTRIBUTE;
import static com.dangdang.ddframe.job.lite.spring.job.parser.common.BaseJobBeanDefinitionParserTag.CRON_ATTRIBUTE;
Expand Down Expand Up @@ -123,7 +122,7 @@ private BeanDefinition createJobCoreBeanDefinition(final Element element) {

private BeanDefinition createJobPropertiesBeanDefinition(final Element element) {
BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(JobProperties.class);
Map<JobPropertiesEnum, String> map = new LinkedHashMap<>(JobPropertiesEnum.values().length, 1);
EnumMap<JobPropertiesEnum, String> map = new EnumMap<>(JobPropertiesEnum.class);
map.put(JobPropertiesEnum.EXECUTOR_SERVICE_HANDLER, element.getAttribute(EXECUTOR_SERVICE_HANDLER_ATTRIBUTE));
map.put(JobPropertiesEnum.JOB_EXCEPTION_HANDLER, element.getAttribute(JOB_EXCEPTION_HANDLER_ATTRIBUTE));
result.addConstructorArgValue(map);
Expand Down

0 comments on commit ac34ca6

Please sign in to comment.