Skip to content

Commit 7fcedd3

Browse files
authored
Merge pull request #103 from sdstolworthy/multiple-hosting-envs
Multiple Hosting Environments
2 parents 2cd0674 + 76e13ba commit 7fcedd3

File tree

6 files changed

+152
-194
lines changed

6 files changed

+152
-194
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.applier/roles
22
.idea/
33
.adhoc
4+
.env
45

56
# Created by https://www.gitignore.io/api/code,java,linux,macos,windows,eclipse,java-web,intellij
67
# Edit at https://www.gitignore.io/?templates=code,java,linux,macos,windows,eclipse,java-web,intellij

src/main/java/com/redhat/labs/lodestar/models/Engagement.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,12 @@ public class Engagement {
3232
private String technicalLeadEmail;
3333
private String customerContactName;
3434
private String customerContactEmail;
35-
private String ocpCloudProviderName;
36-
private String ocpCloudProviderRegion;
37-
private String ocpVersion;
38-
private String ocpSubDomain;
39-
private String ocpPersistentStorageSize;
40-
private String ocpClusterSize;
4135
private boolean publicReference;
4236
private String additionalDetails;
4337
private Launch launch;
4438
private List<EngagementUser> engagementUsers;
45-
39+
private List<HostingEnvironment> hostingEnvironments;
40+
4641
private Status status;
4742
private List<Commit> commits;
4843
private CreationDetails creationDetails;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.redhat.labs.lodestar.models;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class HostingEnvironment {
13+
private String id;
14+
15+
private String additionalDetails;
16+
17+
private String ocpCloudProviderName;
18+
19+
private String ocpCloudProviderRegion;
20+
21+
private String ocpPersistentStorageSize;
22+
23+
private String ocpSubDomain;
24+
25+
private String ocpVersion;
26+
27+
private String environmentName;
28+
29+
private String ocpClusterSize;
30+
}

src/main/java/com/redhat/labs/lodestar/resource/EngagementResource.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,67 +58,72 @@ public Response createEngagement(Engagement engagement, @Context UriInfo uriInfo
5858
@Counted(name = "get-all-engagement", description = "Count of get all engagements")
5959
@Timed(name = "performedEngagementGetAll", description = "Time to get all engagements", unit = MetricUnits.MILLISECONDS)
6060
public Response findAllEngagements() {
61-
61+
6262
List<Engagement> engagements = engagementService.getAllEngagements();
6363
return Response.ok().entity(engagements).build();
6464
}
65-
65+
6666
@GET
6767
@Path("/namespace/{namespace}")
6868
@Counted(name = "get-engagement-namespace", description = "Count of get by id or namespace")
6969
@Timed(name = "performedEngagementGetByNamespace", description = "Time to get an engagement by namespace", unit = MetricUnits.MILLISECONDS)
70-
public Response getEngagement(@PathParam("namespace") String namespace, @QueryParam("includeStatus") boolean includeStatus) {
70+
public Response getEngagement(@PathParam("namespace") String namespace,
71+
@QueryParam("includeStatus") boolean includeStatus) {
7172

7273
Engagement response = engagementService.getEngagement(namespace, includeStatus);
7374
return Response.ok().entity(response).build();
7475
}
75-
76+
7677
@GET
7778
@Path("/customer/{customer}/{engagement}")
7879
@Counted(name = "get-engagement", description = "Count of get engagement")
7980
@Timed(name = "performedEngagementGet", description = "Time to get an engagement", unit = MetricUnits.MILLISECONDS)
80-
public Response getEngagement(@PathParam("customer") String customer, @PathParam("engagement") String engagement, @QueryParam("includeStatus") boolean includeStatus) {
81-
81+
public Response getEngagement(@PathParam("customer") String customer, @PathParam("engagement") String engagement,
82+
@QueryParam("includeStatus") boolean includeStatus) {
83+
8284
Engagement response = engagementService.getEngagement(customer, engagement, includeStatus);
8385
return Response.ok().entity(response).build();
8486
}
85-
87+
8688
@POST
8789
@Path("customer/{customer}/{engagement}/hooks")
8890
@Counted(name = "create-engagement-hook", description = "Count of create-hook requestst")
8991
@Timed(name = "performedHookCreate", description = "Time to create hook", unit = MetricUnits.MILLISECONDS)
90-
public Response createProjectHook(Hook hook, @PathParam("customer") String customer, @PathParam("engagement") String engagement) {
91-
92+
public Response createProjectHook(Hook hook, @PathParam("customer") String customer,
93+
@PathParam("engagement") String engagement) {
94+
9295
Response response = engagementService.createHook(customer, engagement, hook);
9396
return response;
9497
}
95-
98+
9699
@GET
97100
@Path("/customer/{customer}/{engagement}/commits")
98101
@Counted(name = "get-engagement-commits", description = "Count of get engagement commits")
99102
@Timed(name = "performedEngagementCommitsGet", description = "Time to get engagement commits", unit = MetricUnits.MILLISECONDS)
100-
public Response getEngagementCommits(@PathParam("customer") String customer, @PathParam("engagement") String engagement) {
101-
103+
public Response getEngagementCommits(@PathParam("customer") String customer,
104+
@PathParam("engagement") String engagement) {
105+
102106
List<Commit> commitList = engagementService.getCommitLog(customer, engagement);
103107
return Response.ok().entity(commitList).build();
104108
}
105-
109+
106110
@GET
107111
@Path("customer/{customer}/{engagement}/hooks")
108112
@Counted(name = "get-hook", description = "Count of get-hook requests")
109113
@Timed(name = "performedHookGetAll", description = "Time to get all hooks", unit = MetricUnits.MILLISECONDS)
110-
public Response findAllProjectHooks(@PathParam("customer") String customer, @PathParam("engagement") String engagement) {
111-
114+
public Response findAllProjectHooks(@PathParam("customer") String customer,
115+
@PathParam("engagement") String engagement) {
116+
112117
List<Hook> engagements = engagementService.getHooks(customer, engagement);
113118
return Response.ok().entity(engagements).build();
114119
}
115-
120+
116121
@GET
117122
@Path("customer/{customer}/{engagement}/status")
118123
@Counted(name = "get-status", description = "Count of get-status requests")
119124
@Timed(name = "performedStatusGet", description = "Time to get status", unit = MetricUnits.MILLISECONDS)
120125
public Response getStatus(@PathParam("customer") String customer, @PathParam("engagement") String engagement) {
121-
126+
122127
Status status = engagementService.getProjectStatus(customer, engagement);
123128
return Response.ok().entity(status).build();
124129
}

src/main/java/com/redhat/labs/lodestar/service/EngagementService.java

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class EngagementService {
3737
private static final String DEFAULT_BRANCH = "master";
3838
private static final String ENGAGEMENT_FILE = "engagement.json";
3939
private static final String STATUS_FILE = "status.json";
40-
40+
4141
private String engagementPathPrefix;
4242

4343
@ConfigProperty(name = "engagements.repository.id")
@@ -54,7 +54,7 @@ public class EngagementService {
5454

5555
@Inject
5656
FileService fileService;
57-
57+
5858
@Inject
5959
HookService hookService;
6060

@@ -63,15 +63,15 @@ public class EngagementService {
6363

6464
@Inject
6565
JsonMarshaller json;
66-
66+
6767
@Inject
6868
ConfigService configService;
69-
69+
7070
@PostConstruct
7171
public void setPathPrefix() {
7272
Optional<Group> groupOption = groupService.getGitLabGroupByById(engagementRepositoryId);
73-
74-
if(groupOption.isPresent()) {
73+
74+
if (groupOption.isPresent()) {
7575
engagementPathPrefix = groupOption.get().getFullPath();
7676
LOGGER.info("Engagement repo set- to {}", engagementPathPrefix);
7777
} else {
@@ -94,8 +94,8 @@ public Project createEngagement(Engagement engagement, String author, String aut
9494
repoFiles.add(createEngagmentFile(engagement));
9595

9696
// create actions for multiple commit
97-
CommitMultiple commit = createCommitMultiple(repoFiles, project.getId(), DEFAULT_BRANCH, author,
98-
authorEmail, project.isFirst(), commitMessageOptional);
97+
CommitMultiple commit = createCommitMultiple(repoFiles, project.getId(), DEFAULT_BRANCH, author, authorEmail,
98+
project.isFirst(), commitMessageOptional);
9999

100100
if (LOGGER.isDebugEnabled()) {
101101
commit.getActions().stream().forEach(file -> LOGGER.debug("Action File path :: {}", file.getFilePath()));
@@ -105,12 +105,12 @@ public Project createEngagement(Engagement engagement, String author, String aut
105105
if (!fileService.createFiles(project.getId(), commit)) {
106106
throw new UnexpectedGitLabResponseException("failed to commit files for engagement creation.");
107107
}
108-
108+
109109
List<HookConfig> hookConfigs = configService.getHookConfig();
110110
hookConfigs.stream().forEach(hookC -> {
111-
Hook hook = Hook.builder().projectId(engagement.getProjectId()).pushEvents(true)
112-
.url(hookC.getBaseUrl()).token(hookC.getToken()).build();
113-
if(project.isFirst()) { //No need to check for existing hooks first time
111+
Hook hook = Hook.builder().projectId(engagement.getProjectId()).pushEvents(true).url(hookC.getBaseUrl())
112+
.token(hookC.getToken()).build();
113+
if (project.isFirst()) { // No need to check for existing hooks first time
114114
hookService.createProjectHook(engagement.getProjectId(), hook);
115115
} else {
116116
hookService.createOrUpdateProjectHook(engagement.getProjectId(), hook);
@@ -120,54 +120,55 @@ public Project createEngagement(Engagement engagement, String author, String aut
120120
return project;
121121

122122
}
123-
123+
124124
public List<Commit> getCommitLog(String customerName, String engagementName) {
125125
String projectPath = GitLabPathUtils.getPath(engagementPathPrefix, customerName, engagementName);
126126
return projectService.getCommitLog(projectPath);
127127
}
128-
128+
129129
public List<Hook> getHooks(String customer, String engagment) {
130130
Optional<Project> project = getProject(customer, engagment);
131-
132-
if(project.isPresent()) {
131+
132+
if (project.isPresent()) {
133133
return hookService.getProjectHooks(project.get().getId());
134134
}
135-
135+
136136
return new ArrayList<>();
137137
}
138-
138+
139139
public Response createHook(String customerName, String engagementName, Hook hook) {
140-
Response created = Response.status(javax.ws.rs.core.Response.Status.BAD_REQUEST).entity("project doesn't exist").build();
140+
Response created = Response.status(javax.ws.rs.core.Response.Status.BAD_REQUEST).entity("project doesn't exist")
141+
.build();
141142
Optional<Project> optional = getProject(customerName, engagementName);
142-
143-
if(optional.isPresent()) {
143+
144+
if (optional.isPresent()) {
144145
List<Hook> hooks = hookService.getProjectHooks(optional.get().getId());
145146
boolean hookExists = hooks.stream().anyMatch(h -> h.getUrl().equals(hook.getUrl()));
146-
if(!hookExists) {
147+
if (!hookExists) {
147148
created = hookService.createProjectHook(optional.get().getId(), hook);
148149
}
149150
}
150-
151+
151152
return created;
152153
}
153-
154+
154155
public Status getProjectStatus(String customerName, String engagementName) {
155156
Status status = null;
156-
Optional<File> file = fileService.getFile(GitLabPathUtils.getPath(engagementPathPrefix, customerName, engagementName), STATUS_FILE);
157-
if(file.isPresent()) {
157+
Optional<File> file = fileService
158+
.getFile(GitLabPathUtils.getPath(engagementPathPrefix, customerName, engagementName), STATUS_FILE);
159+
if (file.isPresent()) {
158160
status = json.fromJson(file.get().getContent(), Status.class);
159161
}
160-
162+
161163
return status;
162164
}
163-
165+
164166
public Optional<Project> getProject(String customerName, String engagementName) {
165167
String fullPath = GitLabPathUtils.getPath(engagementPathPrefix, customerName, engagementName);
166-
168+
167169
LOGGER.debug("Full path {}", fullPath);
168170
return projectService.getProjectByIdOrPath(fullPath);
169171
}
170-
171172

172173
/**
173174
* Gets all engagements from the base group Structure is BaseGroup - customer
@@ -181,17 +182,11 @@ public List<Engagement> getAllEngagements() {
181182

182183
List<Project> projects = projectService.getProjectsByGroup(engagementRepositoryId, true);
183184

184-
return
185-
projects
186-
.parallelStream()
187-
.map(project -> {
188-
return getEngagement(project, true);
189-
})
190-
.filter(optional -> optional.isPresent())
191-
.map(optional -> {
192-
return optional.get();
193-
})
194-
.collect(Collectors.toList());
185+
return projects.parallelStream().map(project -> {
186+
return getEngagement(project, true);
187+
}).filter(optional -> optional.isPresent()).map(optional -> {
188+
return optional.get();
189+
}).collect(Collectors.toList());
195190

196191
}
197192

@@ -200,48 +195,48 @@ public Engagement getEngagement(String namespaceOrId, boolean includeStatus) {
200195

201196
Optional<Project> project = projectService.getProjectByIdOrPath(namespaceOrId);
202197

203-
if(project.isPresent()) {
198+
if (project.isPresent()) {
204199
engagement = getEngagement(project.get(), includeStatus).orElse(null);
205200
}
206201

207202
return engagement;
208203
}
209-
204+
210205
public Engagement getEngagement(String customerName, String engagementName, boolean includeStatus) {
211206
Engagement engagement = null;
212-
207+
213208
Optional<Project> project = getProject(customerName, engagementName);
214-
215-
if(project.isPresent()) {
209+
210+
if (project.isPresent()) {
216211
engagement = getEngagement(project.get(), includeStatus).orElse(null);
217212
}
218-
213+
219214
return engagement;
220215
}
221-
216+
222217
private Optional<Engagement> getEngagement(Project project, boolean includeStatus) {
223218
Engagement engagement = null;
224-
219+
225220
Optional<File> engagementFile = fileService.getFileAllow404(project.getId(), ENGAGEMENT_FILE);
226221
if (engagementFile.isPresent()) {
227222
engagement = json.fromJson(engagementFile.get().getContent(), Engagement.class);
228-
223+
229224
List<Commit> commits = projectService.getCommitLog(String.valueOf(engagement.getProjectId()));
230225
engagement.setCommits(commits);
231226
}
232-
233-
if(includeStatus && engagement != null) {
227+
228+
if (includeStatus && engagement != null) {
234229
Optional<File> statusFile = fileService.getFileAllow404(project.getId(), STATUS_FILE);
235-
if(statusFile.isPresent()) {
230+
if (statusFile.isPresent()) {
236231
engagement.setStatus(json.fromJson(statusFile.get().getContent(), Status.class));
237232
}
238233
}
239-
234+
240235
return Optional.ofNullable(engagement);
241236
}
242237

243238
private File createEngagmentFile(Engagement engagement) {
244-
//Git api is read only here.
239+
// Git api is read only here.
245240
engagement.setCommits(null);
246241
engagement.setStatus(null);
247242
engagement.setCommitMessage(null);
@@ -259,7 +254,7 @@ private CommitMultiple createCommitMultiple(List<File> filesToCommit, Integer pr
259254
// results
260255
filesToCommit.stream().forEach(file -> actions.add(createAction(file, isNew)));
261256

262-
// use message if provided. otherwise, defaults
257+
// use message if provided. otherwise, defaults
263258
String commitMessage = commitMessageOptional
264259
.orElse(isNew ? commitMessage("Engagement created") : commitMessage("Engagement updated"));
265260

@@ -281,7 +276,7 @@ private String stripPrefix(String in) {
281276
}
282277
return in;
283278
}
284-
279+
285280
private String commitMessage(String message) {
286281
return String.format("%s %s %s", message, getEmoji(), getEmoji());
287282
}

0 commit comments

Comments
 (0)