Skip to content

Commit 8bd9e78

Browse files
Vania XuMike Tutkowski
authored andcommitted
Adding SolidFire API plug-in
1 parent ab8036b commit 8bd9e78

11 files changed

Lines changed: 357 additions & 1 deletion

File tree

client/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@
331331
<artifactId>cloud-plugin-host-anti-affinity</artifactId>
332332
<version>${project.version}</version>
333333
</dependency>
334+
<dependency>
335+
<groupId>org.apache.cloudstack</groupId>
336+
<artifactId>cloud-plugin-api-solidfire-intg-test</artifactId>
337+
<version>${project.version}</version>
338+
</dependency>
334339
</dependencies>
335340
<build>
336341
<plugins>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<FindBugsFilter>
23+
24+
25+
</FindBugsFilter>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<artifactId>cloud-plugin-api-solidfire-intg-test</artifactId>
22+
<name>Apache CloudStack Plugin - API SolidFire</name>
23+
<parent>
24+
<groupId>org.apache.cloudstack</groupId>
25+
<artifactId>cloudstack-plugins</artifactId>
26+
<version>4.5.0-SNAPSHOT</version>
27+
<relativePath>../../pom.xml</relativePath>
28+
</parent>
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.apache.cloudstack</groupId>
32+
<artifactId>cloud-plugin-storage-volume-solidfire</artifactId>
33+
<version>${project.version}</version>
34+
</dependency>
35+
</dependencies>
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.apache.maven.plugins</groupId>
40+
<artifactId>maven-surefire-plugin</artifactId>
41+
<configuration>
42+
<argLine>-Xmx1024m</argLine>
43+
<excludes>
44+
<exclude>org/apache/cloudstack/solidfire/integration/*</exclude>
45+
</excludes>
46+
</configuration>
47+
</plugin>
48+
</plugins>
49+
</build>
50+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
name=solidfire-intg-test
18+
parent=api
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
<beans xmlns="http://www.springframework.org/schema/beans"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xmlns:context="http://www.springframework.org/schema/context"
22+
xmlns:aop="http://www.springframework.org/schema/aop"
23+
xsi:schemaLocation="http://www.springframework.org/schema/beans
24+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
25+
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
26+
http://www.springframework.org/schema/context
27+
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
28+
>
29+
30+
<bean id="apiSolidFireServiceImpl" class="org.apache.cloudstack.solidfire.ApiSolidFireServiceImpl"/>
31+
32+
</beans>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 org.apache.cloudstack.api.command.user.solidfire;
18+
19+
import com.cloud.user.Account;
20+
import com.cloud.user.dao.AccountDao;
21+
22+
import javax.inject.Inject;
23+
24+
import org.apache.log4j.Logger;
25+
26+
import org.apache.cloudstack.api.ApiConstants;
27+
import org.apache.cloudstack.api.APICommand;
28+
import org.apache.cloudstack.api.BaseCmd;
29+
import org.apache.cloudstack.api.Parameter;
30+
import org.apache.cloudstack.api.response.ApiSolidFireAccountIdResponse;
31+
import org.apache.cloudstack.context.CallContext;
32+
import org.apache.cloudstack.solidfire.ApiSolidFireService;
33+
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
34+
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
35+
36+
@APICommand(name = "getSolidFireAccountId", responseObject = ApiSolidFireAccountIdResponse.class, description = "Get SolidFire Account ID",
37+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
38+
public class GetSolidFireAccountIdCmd extends BaseCmd {
39+
private static final Logger s_logger = Logger.getLogger(GetSolidFireAccountIdCmd.class.getName());
40+
private static final String s_name = "getsolidfireaccountidresponse";
41+
42+
@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.STRING, description = "CloudStack Account UUID", required = true)
43+
private String accountUuid;
44+
@Parameter(name = ApiConstants.STORAGE_ID, type = CommandType.STRING, description = "Storage Pool UUID", required = true)
45+
private String storagePoolUuid;
46+
47+
@Inject private ApiSolidFireService _apiSolidFireService;
48+
@Inject private AccountDao _accountDao;
49+
@Inject private PrimaryDataStoreDao _storagePoolDao;
50+
51+
/////////////////////////////////////////////////////
52+
/////////////// API Implementation///////////////////
53+
/////////////////////////////////////////////////////
54+
55+
@Override
56+
public String getCommandName() {
57+
return s_name;
58+
}
59+
60+
@Override
61+
public long getEntityOwnerId() {
62+
Account account = CallContext.current().getCallingAccount();
63+
64+
if (account != null) {
65+
return account.getId();
66+
}
67+
68+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
69+
}
70+
71+
@Override
72+
public void execute() {
73+
Account account = _accountDao.findByUuid(accountUuid);
74+
StoragePoolVO storagePool = _storagePoolDao.findByUuid(storagePoolUuid);
75+
76+
ApiSolidFireAccountIdResponse response = _apiSolidFireService.getSolidFireAccountId(account.getId(), storagePool.getId());
77+
78+
response.setResponseName(getCommandName());
79+
response.setObjectName("apisolidfireaccountid");
80+
81+
this.setResponseObject(response);
82+
}
83+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 org.apache.cloudstack.api.response;
18+
19+
import com.cloud.serializer.Param;
20+
21+
import com.google.gson.annotations.SerializedName;
22+
23+
import org.apache.cloudstack.api.BaseResponse;
24+
25+
public class ApiSolidFireAccountIdResponse extends BaseResponse {
26+
@SerializedName("solidFireAccountId")
27+
@Param(description = "SolidFire Account ID")
28+
private long solidFireAccountId;
29+
30+
public ApiSolidFireAccountIdResponse(long sfAccountId) {
31+
solidFireAccountId = sfAccountId;
32+
}
33+
34+
public long getSolidFireAccountId() {
35+
return solidFireAccountId;
36+
}
37+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 org.apache.cloudstack.solidfire;
18+
19+
import com.cloud.utils.component.PluggableService;
20+
21+
import org.apache.cloudstack.api.response.ApiSolidFireAccountIdResponse;
22+
23+
/**
24+
* Provide API for SolidFire integration tests
25+
*
26+
*/
27+
public interface ApiSolidFireService extends PluggableService {
28+
public ApiSolidFireAccountIdResponse getSolidFireAccountId(Long csAccountId, Long storagePoolId);
29+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 org.apache.cloudstack.solidfire;
18+
19+
import java.util.Map;
20+
import java.util.List;
21+
import java.util.ArrayList;
22+
23+
import javax.ejb.Local;
24+
import javax.inject.Inject;
25+
import javax.naming.ConfigurationException;
26+
27+
import org.apache.log4j.Logger;
28+
import org.apache.cloudstack.acl.APIChecker;
29+
import org.apache.cloudstack.storage.datastore.util.SolidFireUtil;
30+
import org.apache.cloudstack.api.response.ApiSolidFireAccountIdResponse;
31+
import org.apache.cloudstack.api.command.user.solidfire.GetSolidFireAccountIdCmd;
32+
import org.springframework.stereotype.Component;
33+
34+
import com.cloud.exception.PermissionDeniedException;
35+
import com.cloud.user.AccountDetailsDao;
36+
import com.cloud.user.AccountDetailVO;
37+
import com.cloud.user.User;
38+
import com.cloud.utils.component.AdapterBase;
39+
40+
@Component
41+
@Local(value = APIChecker.class)
42+
public class ApiSolidFireServiceImpl extends AdapterBase implements APIChecker, ApiSolidFireService {
43+
private static final Logger s_logger = Logger.getLogger(ApiSolidFireServiceImpl.class);
44+
45+
@Inject
46+
private AccountDetailsDao _accountDetailsDao;
47+
48+
@Override
49+
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
50+
super.configure(name, params);
51+
52+
return true;
53+
}
54+
55+
@Override
56+
public ApiSolidFireAccountIdResponse getSolidFireAccountId(Long csAccountId, Long storagePoolId) {
57+
AccountDetailVO accountDetail = _accountDetailsDao.findDetail(csAccountId, SolidFireUtil.getAccountKey(storagePoolId));
58+
String sfAccountId = accountDetail.getValue();
59+
60+
return new ApiSolidFireAccountIdResponse(Long.parseLong(sfAccountId));
61+
}
62+
63+
@Override
64+
public boolean checkAccess(User user, String apiCommandName) throws PermissionDeniedException {
65+
return true;
66+
}
67+
68+
@Override
69+
public List<Class<?>> getCommands() {
70+
List<Class<?>> cmdList = new ArrayList<Class<?>>();
71+
72+
cmdList.add(GetSolidFireAccountIdCmd.class);
73+
74+
return cmdList;
75+
}
76+
}

plugins/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
</build>
3939
<modules>
4040
<module>api/rate-limit</module>
41+
<module>api/solidfire-intg-test</module>
4142
<module>api/discovery</module>
4243
<module>acl/static-role-based</module>
4344
<module>affinity-group-processors/host-anti-affinity</module>

0 commit comments

Comments
 (0)