Skip to content

Commit c9c53fe

Browse files
brigibodrov
authored andcommitted
STRDTORC-312 impl (walmartlabs#168)
* triggers up for organizations
1 parent af765da commit c9c53fe

File tree

52 files changed

+760
-461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+760
-461
lines changed

client/src/main/java/com/walmartlabs/concord/client/InventoryTask.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,42 @@ public class InventoryTask extends AbstractConcordTask {
2121
private static final Logger log = LoggerFactory.getLogger(InventoryTask.class);
2222

2323
public Map<String, Object> ansible(@InjectVariable("context") Context ctx,
24-
String inventoryName, String hostGroupName, String queryName, Map<String, Object> params) throws Exception {
25-
return ansible(ctx, inventoryName, hostGroupName, queryName, params, null);
24+
String orgName, String inventoryName,
25+
String hostGroupName, String queryName, Map<String, Object> params) throws Exception {
26+
return ansible(ctx, orgName, inventoryName, hostGroupName, queryName, params, null);
2627
}
2728

2829
@SuppressWarnings("unchecked")
2930
public Map<String, Object> ansible(@InjectVariable("context") Context ctx,
30-
String inventoryName, String hostGroupName, String queryName, Map<String, Object> params, Map<String, Object> vars) throws Exception {
31+
String orgName, String inventoryName,
32+
String hostGroupName, String queryName, Map<String, Object> params, Map<String, Object> vars) throws Exception {
3133

32-
List<String> hostIps = execQuery(ctx, inventoryName, queryName, params, List.class);
34+
List<String> hostIps = execQuery(ctx, orgName, inventoryName, queryName, params, List.class);
3335
Map<String, Object> hostVars = new HashMap<>();
3436
hostVars.put("hosts", hostIps);
3537
if (vars != null && !vars.isEmpty()) {
3638
hostVars.put("vars", vars);
3739
}
3840

39-
log.info("ansible ['{}', '{}', '{}', '{}'] -> {}", inventoryName, hostGroupName, queryName, params, hostIps != null);
41+
log.info("ansible ['{}', '{}', '{}', '{}', '{}'] -> {}", orgName, inventoryName, hostGroupName, queryName, params, hostIps != null);
4042

4143
return Collections.singletonMap(hostGroupName, hostVars);
4244
}
4345

4446
@SuppressWarnings("unchecked")
4547
public List<Object> query(@InjectVariable("context") Context ctx,
46-
String inventoryName, String queryName, Map<String, Object> params) throws Exception {
48+
String orgName, String inventoryName, String queryName, Map<String, Object> params) throws Exception {
4749

48-
List<Object> result = execQuery(ctx, inventoryName, queryName, params, List.class);
50+
List<Object> result = execQuery(ctx, orgName, inventoryName, queryName, params, List.class);
4951

50-
log.info("query ['{}', '{}', '{}'] -> {}", inventoryName, queryName, params, result != null);
52+
log.info("query ['{}', '{}', '{}', '{}'] -> {}", orgName, inventoryName, queryName, params, result != null);
5153

5254
return result;
5355
}
5456

55-
private <T> T execQuery(Context ctx, String inventoryName, String queryName, Map<String, Object> params, Class<T> clazz) throws Exception {
57+
private <T> T execQuery(Context ctx, String orgName, String inventoryName, String queryName, Map<String, Object> params, Class<T> clazz) throws Exception {
5658
Map<String, Object> cfg = createTaskCfg(ctx);
57-
String target = String.format("%s/api/v1/inventory/%s/query/%s/exec", get(cfg, Keys.BASEURL_KEY), inventoryName, queryName);
59+
String target = String.format("%s/api/v1/org/%s/inventory/%s/query/%s/exec", get(cfg, Keys.BASEURL_KEY), orgName, inventoryName, queryName);
5860
String sessionToken = get(cfg, SESSION_TOKEN_KEY);
5961

6062
URL url = new URL(target);

client/src/main/java/com/walmartlabs/concord/client/LandingPageRefreshTask.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
@Named("landingPageRefresh")
1515
public class LandingPageRefreshTask extends AbstractConcordTask implements Task {
1616

17+
private static final String ORG_KEY = "org";
1718
private static final String REPOSITORY_KEY = "repository";
1819
private static final String PROJECT_KEY = "project";
1920

2021
@Override
2122
public void execute(Context ctx) throws Exception {
22-
Map<String, Object> cfg = createCfg(ctx, BASEURL_KEY, REPOSITORY_KEY, PROJECT_KEY);
23+
Map<String, Object> cfg = createCfg(ctx, BASEURL_KEY, ORG_KEY, REPOSITORY_KEY, PROJECT_KEY);
24+
String orgName = get(cfg, ORG_KEY);
2325
String projectName = get(cfg, PROJECT_KEY);
2426
String repositoryName = get(cfg, REPOSITORY_KEY);
2527

26-
String target = get(cfg, BASEURL_KEY) + "/api/v1/landing_page/refresh/" + projectName + "/" + repositoryName;
28+
String target = get(cfg, BASEURL_KEY) + "/api/v1/org/" + orgName + "/landing_page/refresh/" + projectName + "/" + repositoryName;
2729
String sessionToken = get(cfg, SESSION_TOKEN_KEY);
2830

2931
URL url = new URL(target);

client/src/main/java/com/walmartlabs/concord/client/TriggerRefreshTask.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
@Named("triggersRefresh")
1515
public class TriggerRefreshTask extends AbstractConcordTask implements Task {
1616

17+
private static final String ORG_KEY = "org";
1718
private static final String REPOSITORY_KEY = "repository";
1819
private static final String PROJECT_KEY = "project";
1920

2021
@Override
2122
public void execute(Context ctx) throws Exception {
22-
Map<String, Object> cfg = createCfg(ctx, BASEURL_KEY, REPOSITORY_KEY, PROJECT_KEY);
23+
Map<String, Object> cfg = createCfg(ctx, BASEURL_KEY, ORG_KEY, REPOSITORY_KEY, PROJECT_KEY);
24+
String orgName = get(cfg, ORG_KEY);
2325
String projectName = get(cfg, PROJECT_KEY);
2426
String repositoryName = get(cfg, REPOSITORY_KEY);
2527

26-
String target = get(cfg, BASEURL_KEY) + "/api/v1/triggers/refresh/" + projectName + "/" + repositoryName;
28+
String target = get(cfg, BASEURL_KEY) + "/api/v1/org/" + orgName + "/trigger/refresh/" + projectName + "/" + repositoryName;
2729
String sessionToken = get(cfg, SESSION_TOKEN_KEY);
2830

2931
URL url = new URL(target);

examples/inventory/concord.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ flows:
1414
- task: ansible
1515
in:
1616
# arguments: inventory name, ansible host group name, query name, query params, additional inventory variables
17-
inventory: "${inventory.ansible('myInventory', 'myHostsGroup', 'endpointsByZypperVersion', {'facter_zypper_version': '1.6.333'}, myVars)}"
17+
inventory: "${inventory.ansible('Default', 'myInventory', 'myHostsGroup', 'endpointsByZypperVersion', {'facter_zypper_version': '1.6.333'}, myVars)}"
1818
# will produce a JSON structure like this:
1919
# {
2020
# "myHostsGroup": {

it/server/src/test/java/com/walmartlabs/concord/it/server/CrudIT.java

+27-29
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
import com.googlecode.junittoolbox.ParallelRunner;
44
import com.sun.org.apache.xml.internal.security.utils.Base64;
5+
import com.walmartlabs.concord.server.api.GenericOperationResultResponse;
56
import com.walmartlabs.concord.server.api.OperationResult;
67
import com.walmartlabs.concord.server.api.PerformedActionType;
7-
import com.walmartlabs.concord.server.api.inventory.*;
8-
import com.walmartlabs.concord.server.api.landing.CreateLandingResponse;
9-
import com.walmartlabs.concord.server.api.landing.DeleteLandingResponse;
10-
import com.walmartlabs.concord.server.api.landing.LandingEntry;
11-
import com.walmartlabs.concord.server.api.landing.LandingPageResource;
8+
import com.walmartlabs.concord.server.api.org.inventory.*;
9+
import com.walmartlabs.concord.server.api.org.landing.CreateLandingResponse;
10+
import com.walmartlabs.concord.server.api.org.landing.LandingEntry;
11+
import com.walmartlabs.concord.server.api.org.landing.LandingPageResource;
1212
import com.walmartlabs.concord.server.api.org.project.ProjectEntry;
1313
import com.walmartlabs.concord.server.api.org.project.RepositoryEntry;
14+
import com.walmartlabs.concord.server.api.org.secret.SecretEntry;
1415
import com.walmartlabs.concord.server.api.org.team.TeamEntry;
1516
import com.walmartlabs.concord.server.api.org.team.TeamUserEntry;
16-
import com.walmartlabs.concord.server.api.org.secret.SecretEntry;
1717
import com.walmartlabs.concord.server.api.project.CreateProjectResponse;
1818
import com.walmartlabs.concord.server.api.project.DeleteProjectResponse;
1919
import com.walmartlabs.concord.server.api.project.ProjectResource;
@@ -113,24 +113,24 @@ public void testLdapMappings() throws Exception {
113113
public void testInventory() throws Exception {
114114
InventoryResource inventoryResource = proxy(InventoryResource.class);
115115

116+
String orgName = OrganizationManager.DEFAULT_ORG_NAME;
116117
String inventoryName = "inventory_" + randomString();
117-
String orgName = "Default";
118118

119119
// --- create
120120

121-
CreateInventoryResponse cir = inventoryResource.createOrUpdate(new InventoryEntry(null, inventoryName, null, orgName, null));
121+
CreateInventoryResponse cir = inventoryResource.createOrUpdate(orgName, new InventoryEntry(inventoryName));
122122
assertTrue(cir.isOk());
123123
assertNotNull(cir.getId());
124124

125125
// --- update
126126

127-
CreateInventoryResponse uir = inventoryResource.createOrUpdate(new InventoryEntry(null, inventoryName, OrganizationManager.DEFAULT_ORG_ID, null, null));
127+
CreateInventoryResponse uir = inventoryResource.createOrUpdate(orgName, new InventoryEntry(inventoryName));
128128
assertTrue(uir.isOk());
129129
assertNotNull(uir.getId());
130130

131131
// --- get
132132

133-
InventoryEntry i1 = inventoryResource.get(inventoryName);
133+
InventoryEntry i1 = inventoryResource.get(orgName, inventoryName);
134134
assertNotNull(i1);
135135
assertNotNull(i1.getId());
136136
assertEquals(uir.getId(), i1.getId());
@@ -140,38 +140,39 @@ public void testInventory() throws Exception {
140140

141141
// --- delete
142142

143-
DeleteInventoryResponse dpr = inventoryResource.delete(inventoryName);
144-
assertTrue(dpr.isOk());
143+
GenericOperationResultResponse dpr = inventoryResource.delete(orgName, inventoryName);
144+
assertTrue(dpr.getResult() == OperationResult.DELETED);
145145
}
146146

147147
@Test(timeout = 30000)
148148
public void testInventoryData() throws Exception {
149149
InventoryDataResource resource = proxy(InventoryDataResource.class);
150150

151+
String orgName = OrganizationManager.DEFAULT_ORG_NAME;
151152
String inventoryName = "inventory_" + randomString();
152153
String itemPath = "/a";
153154
Map<String, Object> data = Collections.singletonMap("k", "v");
154155

155156
InventoryResource inventoryResource = proxy(InventoryResource.class);
156-
inventoryResource.createOrUpdate(new InventoryEntry(null, inventoryName, null, null, null));
157+
inventoryResource.createOrUpdate(orgName, new InventoryEntry(inventoryName));
157158

158159
// --- create
159160

160161
@SuppressWarnings("unchecked")
161-
Map<String, Object> result = (Map<String, Object>) resource.data(inventoryName, itemPath, data);
162+
Map<String, Object> result = (Map<String, Object>) resource.data(orgName, inventoryName, itemPath, data);
162163
assertNotNull(result);
163164
assertEquals(Collections.singletonMap("a", data), result);
164165

165166
// --- get
166167

167168
@SuppressWarnings("unchecked")
168-
Map<String, Object> result2 = (Map<String, Object>) resource.get(inventoryName, itemPath);
169+
Map<String, Object> result2 = (Map<String, Object>) resource.get(orgName, inventoryName, itemPath);
169170
assertNotNull(result2);
170171
assertEquals(Collections.singletonMap("a", data), result);
171172

172173
// --- delete
173174

174-
DeleteInventoryDataResponse didr = resource.delete(inventoryName, itemPath);
175+
DeleteInventoryDataResponse didr = resource.delete(orgName, inventoryName, itemPath);
175176
assertNotNull(didr);
176177
assertTrue(didr.isOk());
177178
}
@@ -180,28 +181,29 @@ public void testInventoryData() throws Exception {
180181
public void testInventoryQuery() throws Exception {
181182
InventoryQueryResource resource = proxy(InventoryQueryResource.class);
182183

184+
String orgName = OrganizationManager.DEFAULT_ORG_NAME;
183185
String inventoryName = "inventory_" + randomString();
184186
String queryName = "queryName_" + randomString();
185187
String text = "text_" + randomString();
186188
;
187189

188190
InventoryResource inventoryResource = proxy(InventoryResource.class);
189-
inventoryResource.createOrUpdate(new InventoryEntry(null, inventoryName, null, null, null));
191+
inventoryResource.createOrUpdate(orgName, new InventoryEntry(inventoryName));
190192

191193
// --- create
192194

193-
CreateInventoryQueryResponse cqr = resource.createOrUpdate(inventoryName, queryName, text);
195+
CreateInventoryQueryResponse cqr = resource.createOrUpdate(orgName, inventoryName, queryName, text);
194196
assertTrue(cqr.isOk());
195197
assertNotNull(cqr.getId());
196198

197199
// --- update
198200
String updatedText = "select cast(json_build_object('k', 'v') as varchar)";
199-
CreateInventoryQueryResponse uqr = resource.createOrUpdate(inventoryName, queryName, updatedText);
201+
CreateInventoryQueryResponse uqr = resource.createOrUpdate(orgName, inventoryName, queryName, updatedText);
200202
assertTrue(uqr.isOk());
201203
assertNotNull(uqr.getId());
202204

203205
// --- get
204-
InventoryQueryEntry e1 = resource.get(inventoryName, queryName);
206+
InventoryQueryEntry e1 = resource.get(orgName, inventoryName, queryName);
205207
assertNotNull(e1);
206208
assertNotNull(e1.getId());
207209
assertEquals(inventoryName, e1.getInventoryName());
@@ -210,13 +212,13 @@ public void testInventoryQuery() throws Exception {
210212

211213
// --- exec
212214
@SuppressWarnings("unchecked")
213-
List<Object> result = resource.exec(inventoryName, queryName, null);
215+
List<Object> result = resource.exec(orgName, inventoryName, queryName, null);
214216
assertNotNull(result);
215217
Map<String, Object> m = (Map<String, Object>) result.get(0);
216218
assertEquals(Collections.singletonMap("k", "v"), m);
217219

218220
// --- delete
219-
DeleteInventoryQueryResponse dqr = resource.delete(inventoryName, queryName);
221+
DeleteInventoryQueryResponse dqr = resource.delete(orgName, inventoryName, queryName);
220222
assertNotNull(dqr);
221223
assertTrue(dqr.isOk());
222224
}
@@ -238,26 +240,22 @@ public void testLanding() throws Exception {
238240

239241
// --- create
240242
LandingEntry entry = new LandingEntry(null, null, null, null, projectName, repositoryName, name, description, icon);
241-
CreateLandingResponse result = resource.createOrUpdate(entry);
243+
CreateLandingResponse result = resource.createOrUpdate(OrganizationManager.DEFAULT_ORG_NAME, entry);
242244
assertNotNull(result);
243245
assertTrue(result.isOk());
244246
assertNotNull(result.getId());
245247
assertEquals(OperationResult.CREATED, result.getResult());
246248

247249
// --- update
248-
result = resource.createOrUpdate(new LandingEntry(result.getId(), null, null, null, projectName, repositoryName, name, description, icon));
250+
result = resource.createOrUpdate(OrganizationManager.DEFAULT_ORG_NAME, new LandingEntry(result.getId(), null, null, null, projectName, repositoryName, name, description, icon));
249251
assertNotNull(result);
250252
assertTrue(result.isOk());
251253
assertNotNull(result.getId());
252254
assertEquals(OperationResult.UPDATED, result.getResult());
253255

254256
// --- list
255-
List<LandingEntry> listResult = resource.list();
257+
List<LandingEntry> listResult = resource.list(OrganizationManager.DEFAULT_ORG_NAME);
256258
assertNotNull(listResult);
257-
258-
// --- delete
259-
DeleteLandingResponse deleteResult = resource.delete(result.getId());
260-
assertNotNull(deleteResult);
261259
}
262260

263261
private static ProjectEntry findProject(List<ProjectEntry> l, String name) {

it/server/src/test/java/com/walmartlabs/concord/it/server/ProjectIT.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
import com.walmartlabs.concord.server.api.security.apikey.ApiKeyResource;
1616
import com.walmartlabs.concord.server.api.security.apikey.CreateApiKeyRequest;
1717
import com.walmartlabs.concord.server.api.security.apikey.CreateApiKeyResponse;
18-
import com.walmartlabs.concord.server.api.trigger.TriggerEntry;
19-
import com.walmartlabs.concord.server.api.trigger.TriggerResource;
18+
import com.walmartlabs.concord.server.api.org.trigger.TriggerEntry;
19+
import com.walmartlabs.concord.server.api.org.trigger.TriggerResource;
2020
import com.walmartlabs.concord.server.api.user.CreateUserRequest;
2121
import com.walmartlabs.concord.server.api.user.CreateUserResponse;
2222
import com.walmartlabs.concord.server.api.user.UserResource;
23+
import com.walmartlabs.concord.server.org.OrganizationManager;
2324
import org.eclipse.jgit.api.Git;
2425
import org.eclipse.jgit.revwalk.RevCommit;
2526
import org.junit.Test;
@@ -263,7 +264,7 @@ public void testInitImport() throws Exception {
263264

264265
TriggerResource triggerResource = proxy(TriggerResource.class);
265266
while (true) {
266-
List<TriggerEntry> triggers = triggerResource.list(projectName, repoName);
267+
List<TriggerEntry> triggers = triggerResource.list(OrganizationManager.DEFAULT_ORG_NAME, projectName, repoName);
267268
if (hasCondition("github", "repository", "abc", triggers) &&
268269
hasCondition("github", "repository", "abc2", triggers) &&
269270
hasCondition("oneops", "org", "myOrg", triggers)) {

it/server/src/test/resources/com/walmartlabs/concord/it/server/triggersRefresh/concord.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ flows:
22
default:
33
- task: triggersRefresh
44
in:
5+
org: "Default"
56
repository: "githubTriggers"
67
project: "concordTriggers"

server/api/src/main/java/com/walmartlabs/concord/server/api/inventory/DeleteInventoryResponse.java

-19
This file was deleted.

server/api/src/main/java/com/walmartlabs/concord/server/api/inventory/CreateInventoryQueryResponse.java server/api/src/main/java/com/walmartlabs/concord/server/api/org/inventory/CreateInventoryQueryResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.walmartlabs.concord.server.api.inventory;
1+
package com.walmartlabs.concord.server.api.org.inventory;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
44
import com.fasterxml.jackson.annotation.JsonProperty;

server/api/src/main/java/com/walmartlabs/concord/server/api/inventory/CreateInventoryResponse.java server/api/src/main/java/com/walmartlabs/concord/server/api/org/inventory/CreateInventoryResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.walmartlabs.concord.server.api.inventory;
1+
package com.walmartlabs.concord.server.api.org.inventory;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
44
import com.fasterxml.jackson.annotation.JsonInclude;

server/api/src/main/java/com/walmartlabs/concord/server/api/inventory/DeleteInventoryDataResponse.java server/api/src/main/java/com/walmartlabs/concord/server/api/org/inventory/DeleteInventoryDataResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.walmartlabs.concord.server.api.inventory;
1+
package com.walmartlabs.concord.server.api.org.inventory;
22

33
import java.io.Serializable;
44

server/api/src/main/java/com/walmartlabs/concord/server/api/inventory/DeleteInventoryQueryResponse.java server/api/src/main/java/com/walmartlabs/concord/server/api/org/inventory/DeleteInventoryQueryResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.walmartlabs.concord.server.api.inventory;
1+
package com.walmartlabs.concord.server.api.org.inventory;
22

33
import java.io.Serializable;
44

0 commit comments

Comments
 (0)