From 8bd9e780717dad4d2f4451e4b681f701c45f2793 Mon Sep 17 00:00:00 2001 From: Vania Xu Date: Thu, 10 Jul 2014 11:36:26 -0600 Subject: [PATCH] Adding SolidFire API plug-in --- client/pom.xml | 5 ++ .../findbugsExcludeFilter.xml | 25 ++++++ plugins/api/solidfire-intg-test/pom.xml | 50 +++++++++++ .../solidfire-intg-test/module.properties | 18 ++++ .../spring-solidfire-intg-test-context.xml | 32 +++++++ .../solidfire/GetSolidFireAccountIdCmd.java | 83 +++++++++++++++++++ .../ApiSolidFireAccountIdResponse.java | 37 +++++++++ .../solidfire/ApiSolidFireService.java | 29 +++++++ .../solidfire/ApiSolidFireServiceImpl.java | 76 +++++++++++++++++ plugins/pom.xml | 1 + .../storage/datastore/util/SolidFireUtil.java | 2 +- 11 files changed, 357 insertions(+), 1 deletion(-) create mode 100644 plugins/api/solidfire-intg-test/findbugsExcludeFilter.xml create mode 100644 plugins/api/solidfire-intg-test/pom.xml create mode 100644 plugins/api/solidfire-intg-test/resources/META-INF/cloudstack/solidfire-intg-test/module.properties create mode 100644 plugins/api/solidfire-intg-test/resources/META-INF/cloudstack/solidfire-intg-test/spring-solidfire-intg-test-context.xml create mode 100644 plugins/api/solidfire-intg-test/src/org/apache/cloudstack/api/command/user/solidfire/GetSolidFireAccountIdCmd.java create mode 100644 plugins/api/solidfire-intg-test/src/org/apache/cloudstack/api/response/ApiSolidFireAccountIdResponse.java create mode 100644 plugins/api/solidfire-intg-test/src/org/apache/cloudstack/solidfire/ApiSolidFireService.java create mode 100644 plugins/api/solidfire-intg-test/src/org/apache/cloudstack/solidfire/ApiSolidFireServiceImpl.java diff --git a/client/pom.xml b/client/pom.xml index 29fef4f335e..46933d92c02 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -331,6 +331,11 @@ cloud-plugin-host-anti-affinity ${project.version} + + org.apache.cloudstack + cloud-plugin-api-solidfire-intg-test + ${project.version} + diff --git a/plugins/api/solidfire-intg-test/findbugsExcludeFilter.xml b/plugins/api/solidfire-intg-test/findbugsExcludeFilter.xml new file mode 100644 index 00000000000..d37285017e8 --- /dev/null +++ b/plugins/api/solidfire-intg-test/findbugsExcludeFilter.xml @@ -0,0 +1,25 @@ + + + + + + diff --git a/plugins/api/solidfire-intg-test/pom.xml b/plugins/api/solidfire-intg-test/pom.xml new file mode 100644 index 00000000000..0707461ce64 --- /dev/null +++ b/plugins/api/solidfire-intg-test/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + cloud-plugin-api-solidfire-intg-test + Apache CloudStack Plugin - API SolidFire + + org.apache.cloudstack + cloudstack-plugins + 4.5.0-SNAPSHOT + ../../pom.xml + + + + org.apache.cloudstack + cloud-plugin-storage-volume-solidfire + ${project.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -Xmx1024m + + org/apache/cloudstack/solidfire/integration/* + + + + + + diff --git a/plugins/api/solidfire-intg-test/resources/META-INF/cloudstack/solidfire-intg-test/module.properties b/plugins/api/solidfire-intg-test/resources/META-INF/cloudstack/solidfire-intg-test/module.properties new file mode 100644 index 00000000000..a6460b93920 --- /dev/null +++ b/plugins/api/solidfire-intg-test/resources/META-INF/cloudstack/solidfire-intg-test/module.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +name=solidfire-intg-test +parent=api \ No newline at end of file diff --git a/plugins/api/solidfire-intg-test/resources/META-INF/cloudstack/solidfire-intg-test/spring-solidfire-intg-test-context.xml b/plugins/api/solidfire-intg-test/resources/META-INF/cloudstack/solidfire-intg-test/spring-solidfire-intg-test-context.xml new file mode 100644 index 00000000000..1bab7349caa --- /dev/null +++ b/plugins/api/solidfire-intg-test/resources/META-INF/cloudstack/solidfire-intg-test/spring-solidfire-intg-test-context.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/api/command/user/solidfire/GetSolidFireAccountIdCmd.java b/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/api/command/user/solidfire/GetSolidFireAccountIdCmd.java new file mode 100644 index 00000000000..f4c0076f867 --- /dev/null +++ b/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/api/command/user/solidfire/GetSolidFireAccountIdCmd.java @@ -0,0 +1,83 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.command.user.solidfire; + +import com.cloud.user.Account; +import com.cloud.user.dao.AccountDao; + +import javax.inject.Inject; + +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.ApiSolidFireAccountIdResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.solidfire.ApiSolidFireService; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; + +@APICommand(name = "getSolidFireAccountId", responseObject = ApiSolidFireAccountIdResponse.class, description = "Get SolidFire Account ID", + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +public class GetSolidFireAccountIdCmd extends BaseCmd { + private static final Logger s_logger = Logger.getLogger(GetSolidFireAccountIdCmd.class.getName()); + private static final String s_name = "getsolidfireaccountidresponse"; + + @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.STRING, description = "CloudStack Account UUID", required = true) + private String accountUuid; + @Parameter(name = ApiConstants.STORAGE_ID, type = CommandType.STRING, description = "Storage Pool UUID", required = true) + private String storagePoolUuid; + + @Inject private ApiSolidFireService _apiSolidFireService; + @Inject private AccountDao _accountDao; + @Inject private PrimaryDataStoreDao _storagePoolDao; + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Account account = CallContext.current().getCallingAccount(); + + if (account != null) { + return account.getId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + + @Override + public void execute() { + Account account = _accountDao.findByUuid(accountUuid); + StoragePoolVO storagePool = _storagePoolDao.findByUuid(storagePoolUuid); + + ApiSolidFireAccountIdResponse response = _apiSolidFireService.getSolidFireAccountId(account.getId(), storagePool.getId()); + + response.setResponseName(getCommandName()); + response.setObjectName("apisolidfireaccountid"); + + this.setResponseObject(response); + } +} diff --git a/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/api/response/ApiSolidFireAccountIdResponse.java b/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/api/response/ApiSolidFireAccountIdResponse.java new file mode 100644 index 00000000000..ad77c7495db --- /dev/null +++ b/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/api/response/ApiSolidFireAccountIdResponse.java @@ -0,0 +1,37 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.response; + +import com.cloud.serializer.Param; + +import com.google.gson.annotations.SerializedName; + +import org.apache.cloudstack.api.BaseResponse; + +public class ApiSolidFireAccountIdResponse extends BaseResponse { + @SerializedName("solidFireAccountId") + @Param(description = "SolidFire Account ID") + private long solidFireAccountId; + + public ApiSolidFireAccountIdResponse(long sfAccountId) { + solidFireAccountId = sfAccountId; + } + + public long getSolidFireAccountId() { + return solidFireAccountId; + } +} diff --git a/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/solidfire/ApiSolidFireService.java b/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/solidfire/ApiSolidFireService.java new file mode 100644 index 00000000000..2f01cfd0465 --- /dev/null +++ b/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/solidfire/ApiSolidFireService.java @@ -0,0 +1,29 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.solidfire; + +import com.cloud.utils.component.PluggableService; + +import org.apache.cloudstack.api.response.ApiSolidFireAccountIdResponse; + +/** + * Provide API for SolidFire integration tests + * + */ +public interface ApiSolidFireService extends PluggableService { + public ApiSolidFireAccountIdResponse getSolidFireAccountId(Long csAccountId, Long storagePoolId); +} diff --git a/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/solidfire/ApiSolidFireServiceImpl.java b/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/solidfire/ApiSolidFireServiceImpl.java new file mode 100644 index 00000000000..bbb485c66d9 --- /dev/null +++ b/plugins/api/solidfire-intg-test/src/org/apache/cloudstack/solidfire/ApiSolidFireServiceImpl.java @@ -0,0 +1,76 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.solidfire; + +import java.util.Map; +import java.util.List; +import java.util.ArrayList; + +import javax.ejb.Local; +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; +import org.apache.cloudstack.acl.APIChecker; +import org.apache.cloudstack.storage.datastore.util.SolidFireUtil; +import org.apache.cloudstack.api.response.ApiSolidFireAccountIdResponse; +import org.apache.cloudstack.api.command.user.solidfire.GetSolidFireAccountIdCmd; +import org.springframework.stereotype.Component; + +import com.cloud.exception.PermissionDeniedException; +import com.cloud.user.AccountDetailsDao; +import com.cloud.user.AccountDetailVO; +import com.cloud.user.User; +import com.cloud.utils.component.AdapterBase; + +@Component +@Local(value = APIChecker.class) +public class ApiSolidFireServiceImpl extends AdapterBase implements APIChecker, ApiSolidFireService { + private static final Logger s_logger = Logger.getLogger(ApiSolidFireServiceImpl.class); + + @Inject + private AccountDetailsDao _accountDetailsDao; + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + + return true; + } + + @Override + public ApiSolidFireAccountIdResponse getSolidFireAccountId(Long csAccountId, Long storagePoolId) { + AccountDetailVO accountDetail = _accountDetailsDao.findDetail(csAccountId, SolidFireUtil.getAccountKey(storagePoolId)); + String sfAccountId = accountDetail.getValue(); + + return new ApiSolidFireAccountIdResponse(Long.parseLong(sfAccountId)); + } + + @Override + public boolean checkAccess(User user, String apiCommandName) throws PermissionDeniedException { + return true; + } + + @Override + public List> getCommands() { + List> cmdList = new ArrayList>(); + + cmdList.add(GetSolidFireAccountIdCmd.class); + + return cmdList; + } +} diff --git a/plugins/pom.xml b/plugins/pom.xml index b5e6a61ea62..802e2ea3755 100755 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -38,6 +38,7 @@ api/rate-limit + api/solidfire-intg-test api/discovery acl/static-role-based affinity-group-processors/host-anti-affinity diff --git a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java index 7c09d854939..307ddbc3cec 100644 --- a/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java +++ b/plugins/storage/volume/solidfire/src/org/apache/cloudstack/storage/datastore/util/SolidFireUtil.java @@ -360,7 +360,7 @@ public class SolidFireUtil { return "sfVolumeAccessGroup_" + storagePoolId; } - private static String getAccountKey(long storagePoolId) { + public static String getAccountKey(long storagePoolId) { return SolidFireUtil.ACCOUNT_ID + "_" + storagePoolId; }