Skip to content

Commit 15b8481

Browse files
committed
rename stats to matrix and fix ut
1 parent 92b6af1 commit 15b8481

26 files changed

+178
-238
lines changed

core/src/main/java/com/flowci/core/api/OpenRestController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.flowci.core.api.domain.CreateJobReport;
2323
import com.flowci.core.api.service.OpenRestService;
2424
import com.flowci.core.config.domain.Config;
25-
import com.flowci.core.flow.domain.StatsCounter;
25+
import com.flowci.core.flow.domain.MatrixCounter;
2626
import com.flowci.core.job.domain.JobCache;
2727
import com.flowci.core.job.service.CacheService;
2828
import com.flowci.core.job.service.LoggingService;
@@ -92,7 +92,7 @@ public List<User> listFlowUserEmail(@PathVariable String name) {
9292
@PostMapping("/flow/{name}/stats")
9393
public void addStatsItem(@PathVariable String name,
9494
@Validated @RequestBody AddStatsItem body) {
95-
openRestService.saveStatsForFlow(name, body.getType(), StatsCounter.from(body.getData()));
95+
openRestService.saveStatsForFlow(name, body.getType(), MatrixCounter.from(body.getData()));
9696
}
9797

9898
@PostMapping("/flow/{name}/job/{number}/context")

core/src/main/java/com/flowci/core/api/service/OpenRestService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.flowci.core.api.domain.CreateJobArtifact;
2121
import com.flowci.core.api.domain.CreateJobReport;
2222
import com.flowci.core.config.domain.Config;
23-
import com.flowci.core.flow.domain.StatsCounter;
23+
import com.flowci.core.flow.domain.MatrixCounter;
2424
import com.flowci.core.secret.domain.Secret;
2525
import com.flowci.core.user.domain.User;
2626
import org.springframework.core.io.Resource;
@@ -51,7 +51,7 @@ public interface OpenRestService {
5151
/**
5252
* Save statistic data for flow
5353
*/
54-
void saveStatsForFlow(String flowName, String statsType, StatsCounter counter);
54+
void saveStatsForFlow(String flowName, String statsType, MatrixCounter counter);
5555

5656
/**
5757
* Save uploaded job report with file

core/src/main/java/com/flowci/core/api/service/OpenRestServiceImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import com.flowci.core.config.service.ConfigService;
2525
import com.flowci.core.flow.dao.FlowUserDao;
2626
import com.flowci.core.flow.domain.Flow;
27-
import com.flowci.core.flow.domain.StatsCounter;
27+
import com.flowci.core.flow.domain.MatrixCounter;
2828
import com.flowci.core.flow.service.FlowService;
29-
import com.flowci.core.flow.service.StatsService;
29+
import com.flowci.core.flow.service.MatrixService;
3030
import com.flowci.core.job.dao.JobDao;
3131
import com.flowci.core.job.domain.Job;
3232
import com.flowci.core.job.domain.JobKey;
@@ -69,7 +69,7 @@ public class OpenRestServiceImpl implements OpenRestService {
6969
private SecretService credentialService;
7070

7171
@Autowired
72-
private StatsService statsService;
72+
private MatrixService matrixService;
7373

7474
@Autowired
7575
private ReportService reportService;
@@ -115,10 +115,10 @@ public Resource getResource(Secret secret, String file) {
115115
}
116116

117117
@Override
118-
public void saveStatsForFlow(String flowName, String statsType, StatsCounter counter) {
118+
public void saveStatsForFlow(String flowName, String statsType, MatrixCounter counter) {
119119
Flow flow = flowService.get(flowName);
120120
int today = DateHelper.toIntDay(new Date());
121-
statsService.add(flow.getId(), today, statsType, counter);
121+
matrixService.add(flow.getId(), today, statsType, counter);
122122
}
123123

124124
@Override

core/src/main/java/com/flowci/core/common/domain/Mongoable.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.flowci.core.common.domain;
1818

19+
import com.flowci.core.flow.domain.Flow;
1920
import com.flowci.util.StringHelper;
2021
import lombok.EqualsAndHashCode;
2122
import lombok.Getter;
@@ -26,6 +27,7 @@
2627

2728
import java.io.Serializable;
2829
import java.util.Date;
30+
import java.util.Objects;
2931

3032
/**
3133
* @author yang

core/src/main/java/com/flowci/core/flow/controller/FlowController.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,6 @@ public Flow delete(@PathVariable String name) {
101101
return flow;
102102
}
103103

104-
/**
105-
* Create credential for flow only
106-
*/
107-
@PostMapping("/{name}/secret/rsa")
108-
@Action(FlowAction.SETUP_CREDENTIAL)
109-
public String setupRSACredential(@PathVariable String name, @RequestBody SimpleKeyPair pair) {
110-
return flowService.setSshRsaCredential(name, pair);
111-
}
112-
113-
@PostMapping("/{name}/secret/auth")
114-
@Action(FlowAction.SETUP_CREDENTIAL)
115-
public String setupAuthCredential(@PathVariable String name, @RequestBody SimpleAuthPair pair) {
116-
return flowService.setAuthCredential(name, pair);
117-
}
118-
119104
@PostMapping("/{name}/users")
120105
@Action(FlowAction.ADD_USER)
121106
public List<User> addUsers(@PathVariable String name, @RequestBody String[] emails) {

core/src/main/java/com/flowci/core/flow/controller/StatsController.java renamed to core/src/main/java/com/flowci/core/flow/controller/MatrixController.java

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
import com.flowci.core.common.helper.DateHelper;
2020
import com.flowci.core.flow.domain.Flow;
21-
import com.flowci.core.flow.domain.StatsItem;
22-
import com.flowci.core.flow.domain.StatsType;
21+
import com.flowci.core.flow.domain.MatrixItem;
22+
import com.flowci.core.flow.domain.MatrixType;
2323
import com.flowci.core.flow.service.FlowService;
24-
import com.flowci.core.flow.service.StatsService;
24+
import com.flowci.core.flow.service.MatrixService;
2525
import com.flowci.exception.ArgumentException;
2626
import org.springframework.beans.factory.annotation.Autowired;
2727
import org.springframework.web.bind.annotation.*;
@@ -35,40 +35,40 @@
3535
*/
3636
@RestController
3737
@RequestMapping("/flows")
38-
public class StatsController {
38+
public class MatrixController {
3939

4040
private static final int MaxDays = 31;
4141

4242
@Autowired
4343
private FlowService flowService;
4444

4545
@Autowired
46-
private StatsService statsService;
46+
private MatrixService matrixService;
4747

48-
@GetMapping("/{name}/stats/types")
49-
public List<StatsType> types(@PathVariable String name) {
48+
@GetMapping("/{name}/matrix/types")
49+
public List<MatrixType> types(@PathVariable String name) {
5050
Flow flow = flowService.get(name);
51-
return statsService.getStatsType(flow);
51+
return matrixService.getStatsType(flow);
5252
}
5353

54-
@GetMapping("/{name}/stats/total")
55-
public StatsItem total(@PathVariable String name, @RequestParam String t) {
54+
@GetMapping("/{name}/matrix/total")
55+
public MatrixItem total(@PathVariable String name, @RequestParam String t) {
5656
Flow flow = flowService.get(name);
57-
return statsService.get(flow.getId(), t, StatsItem.ZERO_DAY);
57+
return matrixService.get(flow.getId(), t, MatrixItem.ZERO_DAY);
5858
}
5959

60-
@GetMapping("/{name}/stats")
61-
public List<StatsItem> list(@PathVariable String name,
62-
@RequestParam(required = false) String t,
63-
@RequestParam int from,
64-
@RequestParam int to) {
60+
@GetMapping("/{name}/matrix")
61+
public List<MatrixItem> list(@PathVariable String name,
62+
@RequestParam(required = false) String t,
63+
@RequestParam int from,
64+
@RequestParam int to) {
6565

6666
if (isValidDuration(from, to)) {
6767
throw new ArgumentException("Illegal query argument");
6868
}
6969

7070
Flow flow = flowService.get(name);
71-
return statsService.list(flow.getId(), t, from, to);
71+
return matrixService.list(flow.getId(), t, from, to);
7272
}
7373

7474
private boolean isValidDuration(int from, int to) {
@@ -79,11 +79,6 @@ private boolean isValidDuration(int from, int to) {
7979
return false;
8080
}
8181

82-
if (f.plus(MaxDays, ChronoUnit.DAYS).isAfter(t)) {
83-
return false;
84-
}
85-
86-
return true;
82+
return !f.plus(MaxDays, ChronoUnit.DAYS).isAfter(t);
8783
}
88-
8984
}

core/src/main/java/com/flowci/core/flow/dao/StatsItemDao.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.flowci.core.flow.dao;
1818

19-
import com.flowci.core.flow.domain.StatsItem;
19+
import com.flowci.core.flow.domain.MatrixItem;
2020
import org.springframework.data.domain.Sort;
2121
import org.springframework.data.mongodb.repository.MongoRepository;
2222
import org.springframework.data.mongodb.repository.Query;
@@ -29,15 +29,15 @@
2929
* @author yang
3030
*/
3131
@Repository
32-
public interface StatsItemDao extends MongoRepository<StatsItem, String> {
32+
public interface StatsItemDao extends MongoRepository<MatrixItem, String> {
3333

3434
@Query("{'flowId':?0, 'type': ?1, 'day' : {$gte : ?2, $lte : ?3}}")
35-
List<StatsItem> findByFlowIdAndTypeDayBetween(String flowId, String type, int dayGT, int dayLT, Sort sort);
35+
List<MatrixItem> findByFlowIdAndTypeDayBetween(String flowId, String type, int dayGT, int dayLT, Sort sort);
3636

3737
@Query("{'flowId':?0, 'day' : {$gte : ?1, $lte : ?2}}")
38-
List<StatsItem> findByFlowIdDayBetween(String flowId, int dayGT, int dayLT, Sort sort);
38+
List<MatrixItem> findByFlowIdDayBetween(String flowId, int dayGT, int dayLT, Sort sort);
3939

40-
Optional<StatsItem> findByFlowIdAndDayAndType(String flowId, int day, String type);
40+
Optional<MatrixItem> findByFlowIdAndDayAndType(String flowId, int day, String type);
4141

4242
void deleteByFlowId(String flowId);
4343
}

core/src/main/java/com/flowci/core/flow/domain/CreateOption.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.flowci.core.flow.domain;
1818

1919
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
2021
import com.flowci.util.StringHelper;
2122
import lombok.Data;
2223
import lombok.experimental.Accessors;
@@ -33,11 +34,21 @@ public class CreateOption {
3334
@JsonProperty("title")
3435
private String templateTitle;
3536

37+
/**
38+
* Yaml in base64 format
39+
*/
40+
@JsonProperty("yml")
41+
private String rawYaml;
42+
3643
public boolean hasGroupName() {
3744
return StringHelper.hasValue(groupName);
3845
}
3946

4047
public boolean hasTemplateTitle() {
4148
return StringHelper.hasValue(templateTitle);
4249
}
50+
51+
public boolean hasRawYaml() {
52+
return StringHelper.hasValue(rawYaml);
53+
}
4354
}

core/src/main/java/com/flowci/core/flow/domain/FlowItem.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
import com.flowci.domain.VarValue;
66
import com.flowci.domain.Vars;
77
import com.flowci.util.StringHelper;
8-
import lombok.EqualsAndHashCode;
98
import lombok.Getter;
109
import lombok.Setter;
1110
import org.springframework.data.mongodb.core.index.Indexed;
1211
import org.springframework.data.mongodb.core.mapping.Document;
1312

13+
import java.util.Objects;
14+
15+
1416
@Getter
1517
@Setter
16-
@EqualsAndHashCode(callSuper = true)
1718
@Document("flow")
1819
public class FlowItem extends Mongoable {
1920

@@ -46,4 +47,17 @@ public boolean hasParentId() {
4647
public boolean hasRootParent() {
4748
return hasParentId() && parentId.equals(ROOT_ID);
4849
}
50+
51+
@Override
52+
public int hashCode() {
53+
return Objects.hashCode(getId());
54+
}
55+
56+
@Override
57+
public boolean equals(Object o) {
58+
if (o instanceof Flow) {
59+
return getId().equals(((Flow) o).getId());
60+
}
61+
return false;
62+
}
4963
}

core/src/main/java/com/flowci/core/flow/domain/StatsCounter.java renamed to core/src/main/java/com/flowci/core/flow/domain/MatrixCounter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
/**
2323
* @author yang
2424
*/
25-
public class StatsCounter extends HashMap<String, Float> {
25+
public class MatrixCounter extends HashMap<String, Float> {
2626

27-
public static StatsCounter from(Map<String, Float> data) {
28-
StatsCounter counter = new StatsCounter();
27+
public static MatrixCounter from(Map<String, Float> data) {
28+
MatrixCounter counter = new MatrixCounter();
2929
counter.putAll(data);
3030
return counter;
3131
}
3232

33-
public void add(StatsCounter another) {
33+
public void add(MatrixCounter another) {
3434
for (Map.Entry<String, Float> entry : another.entrySet()) {
3535
String key = entry.getKey();
3636
Float localValue = this.getOrDefault(key, 0.0F);

0 commit comments

Comments
 (0)