Skip to content

Commit f0f33bf

Browse files
author
Kishan Kavala
committed
Added Mock ApiServer, Regions API calls with api keys
1 parent 89779cc commit f0f33bf

70 files changed

Lines changed: 3812 additions & 559 deletions

File tree

Some content is hidden

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

api/src/com/cloud/api/ResponseGenerator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
import com.cloud.api.response.DomainRouterResponse;
3535
import com.cloud.api.response.EventResponse;
3636
import com.cloud.api.response.ExtractResponse;
37+
import com.cloud.api.response.FindAccountResponse;
38+
import com.cloud.api.response.FindDomainResponse;
39+
import com.cloud.api.response.FindUserResponse;
3740
import com.cloud.api.response.FirewallResponse;
3841
import com.cloud.api.response.FirewallRuleResponse;
3942
import com.cloud.api.response.HostResponse;
@@ -344,4 +347,10 @@ public interface ResponseGenerator {
344347
Site2SiteCustomerGatewayResponse createSite2SiteCustomerGatewayResponse(Site2SiteCustomerGateway result);
345348

346349
Site2SiteVpnConnectionResponse createSite2SiteVpnConnectionResponse(Site2SiteVpnConnection result);
350+
351+
FindUserResponse createFindUserResponse(User user);
352+
353+
FindAccountResponse createFindAccountResponse(Account account);
354+
355+
FindDomainResponse createFindDomainResponse(Domain domain);
347356
}

api/src/com/cloud/api/commands/AddRegionCmd.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,26 @@ public class AddRegionCmd extends BaseCmd {
3636
/////////////////////////////////////////////////////
3737
//////////////// API parameters /////////////////////
3838
/////////////////////////////////////////////////////
39-
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Id of the Region")
40-
private Long id;
39+
@Parameter(name=ApiConstants.ID, type=CommandType.INTEGER, required=true, description="Id of the Region")
40+
private Integer id;
4141

4242
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="adds Region with this name")
4343
private String regionName;
4444

4545
@Parameter(name=ApiConstants.END_POINT, type=CommandType.STRING, required=true, description="end_point of the Region")
4646
private String endPoint;
47+
48+
@Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, description="API key")
49+
private String apiKey;
50+
51+
@Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="Secret Key")
52+
private String secretKey;
4753

4854
/////////////////////////////////////////////////////
4955
/////////////////// Accessors ///////////////////////
5056
/////////////////////////////////////////////////////
5157

52-
public Long getId() {
58+
public Integer getId() {
5359
return id;
5460
}
5561

@@ -59,8 +65,16 @@ public String getRegionName() {
5965

6066
public String getEndPoint() {
6167
return endPoint;
62-
}
68+
}
6369

70+
public String getApiKey() {
71+
return apiKey;
72+
}
73+
74+
public String getSecretKey() {
75+
return secretKey;
76+
}
77+
6478
/////////////////////////////////////////////////////
6579
/////////////// API Implementation///////////////////
6680
/////////////////////////////////////////////////////
@@ -77,7 +91,7 @@ public long getEntityOwnerId() {
7791

7892
@Override
7993
public void execute(){
80-
Region region = _regionService.addRegion(getId(), getRegionName(), getEndPoint());
94+
Region region = _regionService.addRegion(getId(), getRegionName(), getEndPoint(), getApiKey(), getSecretKey());
8195
if (region != null) {
8296
RegionResponse response = _responseGenerator.createRegionResponse(region);
8397
response.setResponseName(getCommandName());

api/src/com/cloud/api/commands/CreateAccountCmd.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public class CreateAccountCmd extends BaseCmd {
8686
@Parameter(name=ApiConstants.USER_ID, type=CommandType.STRING, description="User UUID, required for adding account from another Region")
8787
private String userUUID;
8888

89-
@Parameter(name=ApiConstants.REGION_ID, type=CommandType.LONG, description="Id of the Region creating the account")
90-
private Long regionId;
89+
@Parameter(name=ApiConstants.REGION_ID, type=CommandType.INTEGER, description="Id of the Region creating the account")
90+
private Integer regionId;
9191

9292

9393
/////////////////////////////////////////////////////
@@ -152,7 +152,7 @@ public String getUserUUID() {
152152
return userUUID;
153153
}
154154

155-
public Long getRegionId() {
155+
public Integer getRegionId() {
156156
return regionId;
157157
}
158158

api/src/com/cloud/api/commands/CreateDomainCmd.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public class CreateDomainCmd extends BaseCmd {
5353
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.STRING, description="Domain UUID, required for adding domain from another Region")
5454
private String domainUUID;
5555

56-
@Parameter(name=ApiConstants.REGION_ID, type=CommandType.LONG, description="Id of the Region creating the Domain")
57-
private Long regionId;
56+
@Parameter(name=ApiConstants.REGION_ID, type=CommandType.INTEGER, description="Id of the Region creating the Domain")
57+
private Integer regionId;
5858

5959
/////////////////////////////////////////////////////
6060
/////////////////// Accessors ///////////////////////
@@ -76,7 +76,7 @@ public String getDomainUUID() {
7676
return domainUUID;
7777
}
7878

79-
public Long getRegionId() {
79+
public Integer getRegionId() {
8080
return regionId;
8181
}
8282

api/src/com/cloud/api/commands/CreateUserCmd.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public class CreateUserCmd extends BaseCmd {
6868
@Parameter(name=ApiConstants.USER_ID, type=CommandType.STRING, description="User UUID, required for adding account from another Region")
6969
private String userUUID;
7070

71-
@Parameter(name=ApiConstants.REGION_ID, type=CommandType.LONG, description="Id of the Region creating the User")
72-
private Long regionId;
71+
@Parameter(name=ApiConstants.REGION_ID, type=CommandType.INTEGER, description="Id of the Region creating the User")
72+
private Integer regionId;
7373

7474
/////////////////////////////////////////////////////
7575
/////////////////// Accessors ///////////////////////
@@ -111,7 +111,7 @@ public String getUserUUID() {
111111
return userUUID;
112112
}
113113

114-
public Long getRegionId() {
114+
public Integer getRegionId() {
115115
return regionId;
116116
}
117117

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.api.commands;
18+
19+
import org.apache.log4j.Logger;
20+
21+
import com.cloud.api.ApiConstants;
22+
import com.cloud.api.BaseCmd;
23+
import com.cloud.api.IdentityMapper;
24+
import com.cloud.api.Implementation;
25+
import com.cloud.api.Parameter;
26+
import com.cloud.api.response.FindAccountResponse;
27+
import com.cloud.exception.InvalidParameterValueException;
28+
import com.cloud.user.Account;
29+
30+
@Implementation(description="Find account by ID", responseObject=FindAccountResponse.class)
31+
public class FindAccountCmd extends BaseCmd {
32+
public static final Logger s_logger = Logger.getLogger(FindAccountCmd.class.getName());
33+
34+
private static final String s_name = "findaccountresponse";
35+
36+
/////////////////////////////////////////////////////
37+
//////////////// API parameters /////////////////////
38+
/////////////////////////////////////////////////////
39+
40+
@IdentityMapper(entityTableName="account")
41+
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required=true, description = "Id of the account")
42+
private Long id;
43+
44+
/////////////////////////////////////////////////////
45+
/////////////////// Accessors ///////////////////////
46+
/////////////////////////////////////////////////////
47+
48+
public Long getId() {
49+
return id;
50+
}
51+
52+
/////////////////////////////////////////////////////
53+
/////////////// API Implementation///////////////////
54+
/////////////////////////////////////////////////////
55+
56+
@Override
57+
public String getCommandName() {
58+
return s_name;
59+
}
60+
61+
@Override
62+
public long getEntityOwnerId() {
63+
return 0;
64+
}
65+
66+
@Override
67+
public void execute(){
68+
Account result = _accountService.findAccount(getId());
69+
if(result != null){
70+
FindAccountResponse response = _responseGenerator.createFindAccountResponse(result);
71+
response.setResponseName(getCommandName());
72+
this.setResponseObject(response);
73+
} else {
74+
throw new InvalidParameterValueException("Account with specified Id does not exist");
75+
}
76+
}
77+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.api.commands;
18+
19+
import org.apache.log4j.Logger;
20+
21+
import com.cloud.api.ApiConstants;
22+
import com.cloud.api.BaseCmd;
23+
import com.cloud.api.IdentityMapper;
24+
import com.cloud.api.Implementation;
25+
import com.cloud.api.Parameter;
26+
import com.cloud.api.response.FindDomainResponse;
27+
import com.cloud.domain.Domain;
28+
import com.cloud.exception.InvalidParameterValueException;
29+
30+
@Implementation(description="Find account by ID", responseObject=FindDomainResponse.class)
31+
public class FindDomainCmd extends BaseCmd {
32+
public static final Logger s_logger = Logger.getLogger(FindDomainCmd.class.getName());
33+
34+
private static final String s_name = "finddomainresponse";
35+
36+
/////////////////////////////////////////////////////
37+
//////////////// API parameters /////////////////////
38+
/////////////////////////////////////////////////////
39+
40+
@IdentityMapper(entityTableName="domain")
41+
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "Id of the domain")
42+
private Long id;
43+
44+
@Parameter(name = ApiConstants.DOMAIN, type = CommandType.STRING, description = "Path of the domain")
45+
private String domain;
46+
47+
/////////////////////////////////////////////////////
48+
/////////////////// Accessors ///////////////////////
49+
/////////////////////////////////////////////////////
50+
51+
public Long getId() {
52+
return id;
53+
}
54+
55+
public String getDomain() {
56+
return domain;
57+
}
58+
59+
/////////////////////////////////////////////////////
60+
/////////////// API Implementation///////////////////
61+
/////////////////////////////////////////////////////
62+
63+
@Override
64+
public String getCommandName() {
65+
return s_name;
66+
}
67+
68+
@Override
69+
public long getEntityOwnerId() {
70+
return 0;
71+
}
72+
73+
@Override
74+
public void execute(){
75+
Domain result = null;
76+
if(getId() != null){
77+
result = _domainService.getDomain(getId());
78+
} else if (getDomain() != null){
79+
result = _domainService.findDomainByPath(getDomain());
80+
}
81+
82+
if(result != null){
83+
FindDomainResponse response = _responseGenerator.createFindDomainResponse(result);
84+
response.setResponseName(getCommandName());
85+
this.setResponseObject(response);
86+
} else {
87+
throw new InvalidParameterValueException("Domain with specified Id does not exist");
88+
}
89+
}
90+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.api.commands;
18+
19+
import org.apache.log4j.Logger;
20+
21+
import com.cloud.api.ApiConstants;
22+
import com.cloud.api.BaseCmd;
23+
import com.cloud.api.IdentityMapper;
24+
import com.cloud.api.Implementation;
25+
import com.cloud.api.Parameter;
26+
import com.cloud.api.response.FindUserResponse;
27+
import com.cloud.exception.InvalidParameterValueException;
28+
import com.cloud.user.User;
29+
30+
@Implementation(description="Find user by name and domain", responseObject=FindUserResponse.class)
31+
public class FindUserCmd extends BaseCmd {
32+
public static final Logger s_logger = Logger.getLogger(FindUserCmd.class.getName());
33+
34+
private static final String s_name = "finduserresponse";
35+
36+
/////////////////////////////////////////////////////
37+
//////////////// API parameters /////////////////////
38+
/////////////////////////////////////////////////////
39+
40+
@Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required=true, description="find user with specified username")
41+
private String username;
42+
43+
@IdentityMapper(entityTableName="domain")
44+
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, required=true, description = "Domain the user belongs to")
45+
private Long domainId;
46+
47+
/////////////////////////////////////////////////////
48+
/////////////////// Accessors ///////////////////////
49+
/////////////////////////////////////////////////////
50+
51+
public String getUserName() {
52+
return username;
53+
}
54+
55+
public Long getDomainId() {
56+
return domainId;
57+
}
58+
59+
/////////////////////////////////////////////////////
60+
/////////////// API Implementation///////////////////
61+
/////////////////////////////////////////////////////
62+
63+
@Override
64+
public String getCommandName() {
65+
return s_name;
66+
}
67+
68+
@Override
69+
public long getEntityOwnerId() {
70+
return 0;
71+
}
72+
73+
@Override
74+
public void execute(){
75+
User result = _accountService.findUser(getUserName(), getDomainId());
76+
if(result != null){
77+
FindUserResponse response = _responseGenerator.createFindUserResponse(result);
78+
response.setResponseName(getCommandName());
79+
this.setResponseObject(response);
80+
} else {
81+
throw new InvalidParameterValueException("User with specified name and domainId does not exist");
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)