Merge remote-tracking branch 'origin/4.11'

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2018-12-04 16:39:21 +05:30
commit 52f68a273a
8 changed files with 97 additions and 61 deletions

View File

@ -729,7 +729,7 @@ public class Agent implements HandlerFactory, IAgentControl {
_shell.setPersistentProperty(null, KeyStoreUtils.KS_PASSPHRASE_PROPERTY, storedPassword); _shell.setPersistentProperty(null, KeyStoreUtils.KS_PASSPHRASE_PROPERTY, storedPassword);
} }
Script script = new Script(_keystoreSetupPath, 60000, s_logger); Script script = new Script(_keystoreSetupPath, 300000, s_logger);
script.add(agentFile.getAbsolutePath()); script.add(agentFile.getAbsolutePath());
script.add(keyStoreFile); script.add(keyStoreFile);
script.add(storedPassword); script.add(storedPassword);
@ -773,7 +773,7 @@ public class Agent implements HandlerFactory, IAgentControl {
throw new CloudRuntimeException("Unable to save received agent client and ca certificates", e); throw new CloudRuntimeException("Unable to save received agent client and ca certificates", e);
} }
Script script = new Script(_keystoreCertImportPath, 60000, s_logger); Script script = new Script(_keystoreCertImportPath, 300000, s_logger);
script.add(agentFile.getAbsolutePath()); script.add(agentFile.getAbsolutePath());
script.add(keyStoreFile); script.add(keyStoreFile);
script.add(KeyStoreUtils.AGENT_MODE); script.add(KeyStoreUtils.AGENT_MODE);

View File

@ -164,7 +164,7 @@ public class VirtualRoutingResource {
cmd.getKeystorePassword(), cmd.getKeystorePassword(),
cmd.getValidityDays(), cmd.getValidityDays(),
KeyStoreUtils.CSR_FILENAME); KeyStoreUtils.CSR_FILENAME);
ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), KeyStoreUtils.KS_SETUP_SCRIPT, args); ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), KeyStoreUtils.KS_SETUP_SCRIPT, args, Duration.standardMinutes(15));
return new SetupKeystoreAnswer(result.getDetails()); return new SetupKeystoreAnswer(result.getDetails());
} }
@ -182,7 +182,7 @@ public class VirtualRoutingResource {
cmd.getEncodedCaCertificates(), cmd.getEncodedCaCertificates(),
KeyStoreUtils.PKEY_FILENAME, KeyStoreUtils.PKEY_FILENAME,
cmd.getEncodedPrivateKey()); cmd.getEncodedPrivateKey());
ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), KeyStoreUtils.KS_IMPORT_SCRIPT, args); ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), KeyStoreUtils.KS_IMPORT_SCRIPT, args, Duration.standardMinutes(15));
return new SetupCertificateAnswer(result.isSuccess()); return new SetupCertificateAnswer(result.isSuccess());
} }

View File

@ -481,7 +481,7 @@ pip install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz
%config(noreplace) %{_sysconfdir}/%{name}/management/environment.properties %config(noreplace) %{_sysconfdir}/%{name}/management/environment.properties
%config(noreplace) %{_sysconfdir}/%{name}/management/java.security.ciphers %config(noreplace) %{_sysconfdir}/%{name}/management/java.security.ciphers
%config(noreplace) %{_sysconfdir}/%{name}/management/commons-logging.properties %config(noreplace) %{_sysconfdir}/%{name}/management/commons-logging.properties
%attr(0755,root,root) %{_unitdir}/%{name}-management.service %attr(0644,root,root) %{_unitdir}/%{name}-management.service
%attr(0755,cloud,cloud) %{_localstatedir}/run/%{name}-management.pid %attr(0755,cloud,cloud) %{_localstatedir}/run/%{name}-management.pid
%attr(0755,root,root) %{_bindir}/%{name}-setup-management %attr(0755,root,root) %{_bindir}/%{name}-setup-management
%attr(0755,root,root) %{_bindir}/%{name}-update-xenserver-licenses %attr(0755,root,root) %{_bindir}/%{name}-update-xenserver-licenses

View File

@ -28,8 +28,8 @@ Environment="NAME=cloudstack-management"
EnvironmentFile=/etc/default/cloudstack-management EnvironmentFile=/etc/default/cloudstack-management
ExecStartPre=/bin/bash -c "/bin/systemctl set-environment JAVA_HOME=$( readlink -f $( which java ) | sed s:bin/.*$:: )" ExecStartPre=/bin/bash -c "/bin/systemctl set-environment JAVA_HOME=$( readlink -f $( which java ) | sed s:bin/.*$:: )"
ExecStartPre=/bin/bash -c "/bin/systemctl set-environment JARS=$(ls /usr/share/cloudstack-management/lib/*.jar | tr '\n' ':' | sed s'/.$//')" ExecStartPre=/bin/bash -c "/bin/systemctl set-environment JARS=$(ls /usr/share/cloudstack-management/lib/*.jar | tr '\n' ':' | sed s'/.$//')"
ExecStart=/usr/bin/jsvc $JAVA_DEBUG -home "${JAVA_HOME}" -user "${CLOUDSTACK_USER}" -cp "${JARS}:${CLASSPATH}" -errfile ${LOGDIR}/${NAME}.err -cwd ${LOGDIR} -pidfile "${CLOUDSTACK_PID}" ${JAVA_OPTS} "${BOOTSTRAP_CLASS}" ExecStart=/usr/bin/jsvc $JAVA_DEBUG -home "${JAVA_HOME}" -user "${CLOUDSTACK_USER}" -cp "${JARS}:${CLASSPATH}" -errfile "${LOGDIR}/${NAME}.err" -cwd "${LOGDIR}" -pidfile "${CLOUDSTACK_PID}" "${JAVA_OPTS}" "${BOOTSTRAP_CLASS}"
ExecStop=/usr/bin/jsvc -cp "$JARS:$CLASSPATH" -pidfile "$CLOUDSTACK_PID" -stop "$BOOTSTRAP_CLASS" ExecStop=/usr/bin/jsvc -cp "${JARS}:${CLASSPATH}" -pidfile "${CLOUDSTACK_PID}" -stop "${BOOTSTRAP_CLASS}"
SuccessExitStatus=143 SuccessExitStatus=143
[Install] [Install]

View File

@ -16,15 +16,13 @@
// under the License. // under the License.
package org.apache.cloudstack.api.response; package org.apache.cloudstack.api.response;
import java.util.HashSet; import com.cloud.serializer.Param;
import java.util.Set;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param; import java.util.HashSet;
import java.util.Set;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class ApiDiscoveryResponse extends BaseResponse { public class ApiDiscoveryResponse extends BaseResponse {
@ -121,4 +119,8 @@ public class ApiDiscoveryResponse extends BaseResponse {
public void addApiResponse(ApiResponseResponse apiResponse) { public void addApiResponse(ApiResponseResponse apiResponse) {
this.apiResponse.add(apiResponse); this.apiResponse.add(apiResponse);
} }
public Set<ApiResponseResponse> getApiResponse() {
return apiResponse;
}
} }

View File

@ -16,15 +16,13 @@
// under the License. // under the License.
package org.apache.cloudstack.api.response; package org.apache.cloudstack.api.response;
import java.util.HashSet; import com.cloud.serializer.Param;
import java.util.Set;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param; import java.util.HashSet;
import java.util.Set;
public class ApiResponseResponse extends BaseResponse { public class ApiResponseResponse extends BaseResponse {
@SerializedName(ApiConstants.NAME) @SerializedName(ApiConstants.NAME)
@ -61,4 +59,20 @@ public class ApiResponseResponse extends BaseResponse {
} }
this.apiResponse.add(childApiResponse); this.apiResponse.add(childApiResponse);
} }
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getType() {
return type;
}
public Set<ApiResponseResponse> getApiResponse() {
return apiResponse;
}
} }

View File

@ -16,21 +16,13 @@
// under the License. // under the License.
package org.apache.cloudstack.discovery; package org.apache.cloudstack.discovery;
import java.lang.reflect.Field; import com.cloud.serializer.Param;
import java.util.ArrayList; import com.cloud.user.User;
import java.util.HashMap; import com.cloud.utils.ReflectUtil;
import java.util.HashSet; import com.cloud.utils.StringUtils;
import java.util.List; import com.cloud.utils.component.ComponentLifecycleBase;
import java.util.Map; import com.cloud.utils.component.PluggableService;
import java.util.Set;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.acl.APIChecker; import org.apache.cloudstack.acl.APIChecker;
import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseAsyncCmd;
@ -43,13 +35,18 @@ import org.apache.cloudstack.api.response.ApiDiscoveryResponse;
import org.apache.cloudstack.api.response.ApiParameterResponse; import org.apache.cloudstack.api.response.ApiParameterResponse;
import org.apache.cloudstack.api.response.ApiResponseResponse; import org.apache.cloudstack.api.response.ApiResponseResponse;
import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ListResponse;
import org.apache.log4j.Logger;
import org.reflections.ReflectionUtils;
import org.springframework.stereotype.Component;
import com.cloud.serializer.Param; import javax.inject.Inject;
import com.cloud.user.User; import java.lang.reflect.Field;
import com.cloud.utils.ReflectUtil; import java.util.ArrayList;
import com.cloud.utils.StringUtils; import java.util.HashMap;
import com.cloud.utils.component.ComponentLifecycleBase; import java.util.HashSet;
import com.cloud.utils.component.PluggableService; import java.util.List;
import java.util.Map;
import java.util.Set;
@Component @Component
public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements ApiDiscoveryService { public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements ApiDiscoveryService {
@ -100,7 +97,8 @@ public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements A
} }
ApiDiscoveryResponse response = getCmdRequestMap(cmdClass, apiCmdAnnotation); ApiDiscoveryResponse response = getCmdRequestMap(cmdClass, apiCmdAnnotation);
String responseName = apiCmdAnnotation.responseObject().getName(); Class<? extends BaseResponse> responseClass = apiCmdAnnotation.responseObject();
String responseName = responseClass.getName();
if (!responseName.contains("SuccessResponse")) { if (!responseName.contains("SuccessResponse")) {
if (!responseApiNameListMap.containsKey(responseName)) { if (!responseApiNameListMap.containsKey(responseName)) {
responseApiNameListMap.put(responseName, new ArrayList<String>()); responseApiNameListMap.put(responseName, new ArrayList<String>());
@ -109,7 +107,7 @@ public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements A
} }
response.setRelated(responseName); response.setRelated(responseName);
Field[] responseFields = apiCmdAnnotation.responseObject().getDeclaredFields(); Set<Field> responseFields = ReflectionUtils.getAllFields(responseClass);
for (Field responseField : responseFields) { for (Field responseField : responseFields) {
ApiResponseResponse responseResponse = getFieldResponseMap(responseField); ApiResponseResponse responseResponse = getFieldResponseMap(responseField);
response.addApiResponse(responseResponse); response.addApiResponse(responseResponse);

View File

@ -16,34 +16,36 @@
// under the License. // under the License.
package org.apache.cloudstack.discovery; package org.apache.cloudstack.discovery;
import static org.junit.Assert.assertEquals; import com.cloud.user.User;
import static org.junit.Assert.assertFalse; import com.cloud.user.UserVO;
import static org.junit.Assert.assertTrue; import com.cloud.utils.component.PluggableService;
import static org.mockito.Matchers.any; import org.apache.cloudstack.acl.APIChecker;
import static org.mockito.Matchers.anyString; import org.apache.cloudstack.api.APICommand;
import static org.mockito.Mockito.mock; import org.apache.cloudstack.api.command.user.discovery.ListApisCmd;
import static org.mockito.Mockito.when; import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.response.ApiDiscoveryResponse;
import org.apache.cloudstack.api.response.ApiResponseResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.commons.lang.StringUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import javax.naming.ConfigurationException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import javax.naming.ConfigurationException; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.BeforeClass; import static org.junit.Assert.assertNotNull;
import org.junit.Test; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import org.apache.cloudstack.acl.APIChecker; import static org.mockito.Matchers.anyString;
import org.apache.cloudstack.api.APICommand; import static org.mockito.Mockito.mock;
import org.apache.cloudstack.api.command.user.discovery.ListApisCmd; import static org.mockito.Mockito.when;
import org.apache.cloudstack.api.response.ApiDiscoveryResponse;
import org.apache.cloudstack.api.response.ListResponse;
import com.cloud.user.User;
import com.cloud.user.UserVO;
import com.cloud.utils.component.PluggableService;
public class ApiDiscoveryTest { public class ApiDiscoveryTest {
private static APIChecker s_apiChecker = mock(APIChecker.class); private static APIChecker s_apiChecker = mock(APIChecker.class);
@ -51,14 +53,19 @@ public class ApiDiscoveryTest {
private static ApiDiscoveryServiceImpl s_discoveryService = new ApiDiscoveryServiceImpl(); private static ApiDiscoveryServiceImpl s_discoveryService = new ApiDiscoveryServiceImpl();
private static Class<?> testCmdClass = ListApisCmd.class; private static Class<?> testCmdClass = ListApisCmd.class;
private static Class<?> listVMsCmdClass = ListVMsCmd.class;
private static User testUser; private static User testUser;
private static String testApiName; private static String testApiName;
private static String listVmsCmdName;
private static String testApiDescription; private static String testApiDescription;
private static String testApiSince; private static String testApiSince;
private static boolean testApiAsync; private static boolean testApiAsync;
@BeforeClass @BeforeClass
public static void setUp() throws ConfigurationException { public static void setUp() throws ConfigurationException {
listVmsCmdName = listVMsCmdClass.getAnnotation(APICommand.class).name();
testApiName = testCmdClass.getAnnotation(APICommand.class).name(); testApiName = testCmdClass.getAnnotation(APICommand.class).name();
testApiDescription = testCmdClass.getAnnotation(APICommand.class).description(); testApiDescription = testCmdClass.getAnnotation(APICommand.class).description();
testApiSince = testCmdClass.getAnnotation(APICommand.class).since(); testApiSince = testCmdClass.getAnnotation(APICommand.class).since();
@ -75,6 +82,7 @@ public class ApiDiscoveryTest {
Set<Class<?>> cmdClasses = new HashSet<Class<?>>(); Set<Class<?>> cmdClasses = new HashSet<Class<?>>();
cmdClasses.add(ListApisCmd.class); cmdClasses.add(ListApisCmd.class);
cmdClasses.add(ListVMsCmd.class);
s_discoveryService.start(); s_discoveryService.start();
s_discoveryService.cacheResponseMap(cmdClasses); s_discoveryService.cacheResponseMap(cmdClasses);
} }
@ -82,6 +90,7 @@ public class ApiDiscoveryTest {
@Test @Test
public void verifyListSingleApi() throws Exception { public void verifyListSingleApi() throws Exception {
ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>)s_discoveryService.listApis(testUser, testApiName); ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>)s_discoveryService.listApis(testUser, testApiName);
assertNotNull("Responses should not be null", responses);
if (responses != null) { if (responses != null) {
ApiDiscoveryResponse response = responses.getResponses().get(0); ApiDiscoveryResponse response = responses.getResponses().get(0);
assertTrue("No. of response items should be one", responses.getCount() == 1); assertTrue("No. of response items should be one", responses.getCount() == 1);
@ -95,12 +104,25 @@ public class ApiDiscoveryTest {
@Test @Test
public void verifyListApis() throws Exception { public void verifyListApis() throws Exception {
ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>)s_discoveryService.listApis(testUser, null); ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>)s_discoveryService.listApis(testUser, null);
assertNotNull("Responses should not be null", responses);
if (responses != null) { if (responses != null) {
assertTrue("No. of response items > 1", responses.getCount().intValue() == 1); assertTrue("No. of response items > 2", responses.getCount().intValue() == 2);
for (ApiDiscoveryResponse response : responses.getResponses()) { for (ApiDiscoveryResponse response : responses.getResponses()) {
assertFalse("API name is empty", response.getName().isEmpty()); assertFalse("API name is empty", response.getName().isEmpty());
assertFalse("API description is empty", response.getDescription().isEmpty()); assertFalse("API description is empty", response.getDescription().isEmpty());
} }
} }
} }
@Test
public void verifyListVirtualMachinesTagsField() throws Exception {
ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>)s_discoveryService.listApis(testUser, listVmsCmdName);
assertNotNull("Response should not be null", responses);
if (responses != null) {
assertEquals("No. of response items should be one", 1, (int) responses.getCount());
ApiDiscoveryResponse response = responses.getResponses().get(0);
List<ApiResponseResponse> tagsResponse = response.getApiResponse().stream().filter(resp -> StringUtils.equals(resp.getName(), "tags")).collect(Collectors.toList());
assertEquals("Tags field should be present in listVirtualMachines response fields", tagsResponse.size(), 1);
}
}
} }