Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
1ee9980
Initial commit
charles-phiri May 17, 2018
9f7eff1
some code to enhance the configure method in the Service Layer
charles-phiri May 17, 2018
987534e
refactored Service interface
charles-phiri May 17, 2018
4ef4c2f
refactored Service interface
charles-phiri May 23, 2018
6256e91
refactored Service interface
charles-phiri May 23, 2018
c7e5572
refactored Service interface
charles-phiri May 23, 2018
74822ce
refactored Service interface
charles-phiri May 24, 2018
e017c1c
refactored Service interface
charles-phiri May 24, 2018
9438236
refactored Service interface
charles-phiri May 28, 2018
99bb448
refactored Service interface
charles-phiri May 28, 2018
3cdb059
refactored Service interface
charles-phiri May 28, 2018
be2d1b3
refactored Service interface
charles-phiri May 29, 2018
6c76aa9
refactored Service interface
charles-phiri May 29, 2018
1e24faa
refactored Service interface
charles-phiri May 29, 2018
ee7907c
refactored Service interface
charles-phiri May 29, 2018
65b7d38
refactored Service interface
charles-phiri May 29, 2018
182dea9
Removed unused imports
charles-phiri May 29, 2018
395b246
refactored Service interface
charles-phiri May 29, 2018
aae408c
refactored Service interface
charles-phiri May 29, 2018
a4c6d5d
This is a compiled version of the work I have been doing so far. I am…
charles-phiri May 29, 2018
e8aa68b
Changed the schema script which was having errors when deploying the DB.
charles-phiri May 29, 2018
a10c798
Minor fixes on SQL schema file
charles-phiri May 30, 2018
e0292b5
Changed the schema script which was having errors when deploying the DB.
charles-phiri May 30, 2018
64a6185
Refactored some code in the API (Cmd) class.
charles-phiri May 30, 2018
135383d
Added some more functionality in the Service Layer class.
charles-phiri May 30, 2018
2be2e9d
Removed the code that was using generics in the class DiagnosticsKey.
charles-phiri May 30, 2018
943626e
Corrected code in my DiagnosticsConfigDepotImpl class that was using …
charles-phiri May 30, 2018
e187bc1
Corrected code in my RetrieveDiagnosticsVO class that was using the g…
charles-phiri May 30, 2018
98e2aa5
Yet still, removed some code using generics code.
charles-phiri May 30, 2018
3b97954
Added more code in the Service Layer class and refactored code in the…
charles-phiri May 31, 2018
987b6f7
Refactored code in Service Impl class.
charles-phiri May 31, 2018
2ff8287
Added code in spring xml file.
charles-phiri May 31, 2018
351f721
Created my own interface class for DiagnosticsConfigDepotImpl as I co…
charles-phiri May 31, 2018
94a2fb5
Changed most of the code in the DaO and VO classes including its usag…
charles-phiri Jun 4, 2018
8b57ee6
Refactored code in the Dao and VO, and also added one more method to …
charles-phiri Jun 5, 2018
8995e4f
Cleaned up the code and refactored code so that it has some of the ch…
charles-phiri Jun 6, 2018
e6c1029
Refactored code in the Service Layer impl.
charles-phiri Jun 6, 2018
974de4a
Made some code logic changes to the Service Layer when populating the…
charles-phiri Jun 7, 2018
fc5ef6f
Addressed comments on the code.
charles-phiri Jun 7, 2018
ca4dd82
Refactored code in the Service Layer for retrieving recodes from the …
charles-phiri Jun 7, 2018
ca5c308
Added unit test file to test the functionality in the Service Layer i…
charles-phiri Jun 12, 2018
fa129fa
Added unit test file to test the functionality in the Service Layer i…
charles-phiri Jun 12, 2018
e97895f
Removed the duplicated licence information.
charles-phiri Jun 12, 2018
f525aa9
1. Cleaned up code as per Daan's comments.
charles-phiri Jun 13, 2018
3e62161
Mgt-server could be running in a vm that does not have diskOffering. …
charles-phiri Jun 14, 2018
cc880d4
Added code to check capacity of the disk space and compare it to the …
charles-phiri Jun 14, 2018
91514d4
Added code to check capacity of the disk space and compare it to the …
charles-phiri Jun 14, 2018
141ab51
Added code to check capacity of the disk space and compare it to the …
charles-phiri Jun 14, 2018
2e55ec2
Added code to check capacity of the disk space and compare it to the …
charles-phiri Jun 19, 2018
d2b2d62
Added code to check capacity of the disk space and compare it to the …
charles-phiri Jun 20, 2018
45bd812
Added code to parse for a default value which is in square brackets, …
charles-phiri Jun 21, 2018
c9d7ad2
Inserted getters/setters for the script filename variables
charles-phiri Jun 21, 2018
dd5579d
Added skeleton scripts (still adding code) to retrieve files and run …
charles-phiri Jun 26, 2018
46098bc
Added code for the two command classes (ExecuteScriptCommand and Retr…
charles-phiri Jun 27, 2018
5d22c03
Added code for the two command classes (ExecuteScriptCommand and Retr…
charles-phiri Jun 27, 2018
5086e34
Added code for the two command classes (ExecuteScriptCommand and Retr…
charles-phiri Jun 27, 2018
555cc86
Add method to check disk space
charles-phiri Jun 27, 2018
94b414d
Minor changes in unit test
charles-phiri Jun 27, 2018
0f19d46
Still working on unit test
charles-phiri Jun 28, 2018
956a434
Added more unit tests.
charles-phiri Jun 28, 2018
76e5545
Skeleton implementation of the Garbage Collector.
charles-phiri Jun 28, 2018
c458261
Refactored code while testing, mostly in the Service Layer. Added a c…
charles-phiri Jul 8, 2018
9a6c5cf
Got rid of the cyclic dependencies that I was encountering when compi…
charles-phiri Jul 10, 2018
24f123a
Merge branch 'master' of https://github.com/apache/cloudstack into re…
charles-phiri Jul 10, 2018
f66c840
Refactored code in the Service Layer and the python scripts for retri…
charles-phiri Jul 17, 2018
1e4a426
Marvin tests for the RetrieveDiagnostics API
charles-phiri Jul 19, 2018
63f6b9b
Full complete code after refactoring. Addition of copyFileFromSystemV…
charles-phiri Jul 25, 2018
3acbfe4
Code cleanup and refactoring
charles-phiri Jul 26, 2018
d08cc7b
Complete RerieveDiagnostics API implementation for testing.
charles-phiri Jul 27, 2018
3c12e07
Complete RerieveDiagnostics API .
charles-phiri Jul 27, 2018
f88bde0
Minor bug fixes.
charles-phiri Jul 29, 2018
720da4c
Code for the RetrieveDiagnostics API.
charles-phiri Aug 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions api/src/main/java/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
// under the License.
package com.cloud.event;

import java.util.HashMap;
import java.util.Map;

import com.cloud.dc.DataCenter;
import com.cloud.dc.Pod;
import com.cloud.dc.StorageNetworkIpRange;
Expand Down Expand Up @@ -76,6 +73,9 @@
import org.apache.cloudstack.ha.HAConfig;
import org.apache.cloudstack.usage.Usage;

import java.util.HashMap;
import java.util.Map;

public class EventTypes {

//map of Event and corresponding entity for which Event is applicable
Expand All @@ -96,6 +96,7 @@ public class EventTypes {
public static final String EVENT_VM_MOVE = "VM.MOVE";
public static final String EVENT_VM_RESTORE = "VM.RESTORE";
public static final String EVENT_VM_EXPUNGE = "VM.EXPUNGE";
public static final String EVENT_VM_DIAGNOSTICS = "VM.DIAGNOSTICS";

// Domain Router
public static final String EVENT_ROUTER_CREATE = "ROUTER.CREATE";
Expand Down Expand Up @@ -604,6 +605,7 @@ public class EventTypes {
entityEventDetails.put(EVENT_VM_MOVE, VirtualMachine.class);
entityEventDetails.put(EVENT_VM_RESTORE, VirtualMachine.class);
entityEventDetails.put(EVENT_VM_EXPUNGE, VirtualMachine.class);
entityEventDetails.put(EVENT_VM_DIAGNOSTICS, VirtualMachine.class);

entityEventDetails.put(EVENT_ROUTER_CREATE, VirtualRouter.class);
entityEventDetails.put(EVENT_ROUTER_DESTROY, VirtualRouter.class);
Expand Down
9 changes: 9 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public class ApiConstants {
public static final String EXTRA_DHCP_OPTION_NAME = "extradhcpoptionname";
public static final String EXTRA_DHCP_OPTION_CODE = "extradhcpoptioncode";
public static final String EXTRA_DHCP_OPTION_VALUE = "extradhcpvalue";
public static final String EXITCODE = "exitcode";
public static final String FENCE = "fence";
public static final String FETCH_LATEST = "fetchlatest";
public static final String FIRSTNAME = "firstname";
Expand Down Expand Up @@ -289,11 +290,14 @@ public class ApiConstants {
public static final String START_PORT = "startport";
public static final String STATE = "state";
public static final String STATUS = "status";
public static final String STDOUT = "stdout";
public static final String STDERR = "stderr";
public static final String STORAGE_TYPE = "storagetype";
public static final String STORAGE_POLICY = "storagepolicy";
public static final String STORAGE_MOTION_ENABLED = "storagemotionenabled";
public static final String STORAGE_CAPABILITIES = "storagecapabilities";
public static final String SYSTEM_VM_TYPE = "systemvmtype";
public static final String TARGET_ID = "targetid";
public static final String TAGS = "tags";
public static final String TARGET_IQN = "targetiqn";
public static final String TEMPLATE_FILTER = "templatefilter";
Expand Down Expand Up @@ -719,6 +723,11 @@ public class ApiConstants {
public static final String LAST_ANNOTATED = "lastannotated";
public static final String LDAP_DOMAIN = "ldapdomain";

public static final String DETAIL = "detail";
public static final String DISABLE_THRESHOLD = "disablethreshold";
public static final String FILE_PATH = "filepath";
public static final String FILE_AGE = "fileage";

public enum HostDetails {
all, capacity, events, stats, min;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// 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.admin.diagnostics;

import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.vm.VirtualMachine;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiArgValidator;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.RetrieveDiagnosticsResponse;
import org.apache.cloudstack.api.response.SystemVmResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.diagnostics.RetrieveDiagnosticsService;
import org.apache.log4j.Logger;

import javax.inject.Inject;
import javax.naming.ConfigurationException;

@APICommand(name = RetrieveDiagnosticsCmd.APINAME,
description = "Retrieves diagnostics files from host VMs",
responseObject = RetrieveDiagnosticsResponse.class,
entityType = {VirtualMachine.class},
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = false,
since = "4.12.0",
authorized = {RoleType.Admin})
public class RetrieveDiagnosticsCmd extends BaseAsyncCmd {

private static final Logger LOGGER = Logger.getLogger(RetrieveDiagnosticsCmd.class);

public static final String APINAME = "retrieveDiagnostics";

@Inject
private RetrieveDiagnosticsService retrieveDiagnosticsService;

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name = ApiConstants.TARGET_ID,
type = CommandType.UUID,
entityType = SystemVmResponse.class,
validations = {ApiArgValidator.PositiveNumber},
required = true,
description = "the Id of the system VM instance.")
private Long systemVmId;


@Parameter(name = ApiConstants.TYPE,
type = CommandType.STRING,
required = true,
description = "The type of diagnostics files requested, if DIAGNOSTICS_TYPE is not provided then the default files specified in the database will be retrieved")
private String type;

@Parameter(name = ApiConstants.DETAIL,
type = CommandType.STRING,
description = "Optional comma separated list of diagnostics files or items, can be specified as filenames only or full file path. These come in addition to the defaults set in diagnosticstype")
private String optionalListOfFiles;

@Parameter(name = ApiConstants.TIMEOUT,
type = CommandType.STRING,
description = "Time out setting in seconds for the overall API call.")
private String timeOut;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public String getOptionalListOfFiles() {
return optionalListOfFiles;
}

public String getTimeOut() {
return timeOut;
}

public Long getId() {
return systemVmId;
}

@Override
public String getEventType() {
VirtualMachine.Type type = _mgr.findSystemVMTypeById(getId());
return type.toString();
}
public String getType() {
return type;
}

@Override
public String getCommandName() {
return APINAME.toLowerCase() + BaseAsyncCmd.RESPONSE_SUFFIX;
}

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}

@Override
public String getEventDescription() {
return "Retrieved diagnostics files from host =" + systemVmId;
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
RetrieveDiagnosticsResponse response = new RetrieveDiagnosticsResponse();

try {
final String url = retrieveDiagnosticsService.getDiagnosticsFiles(this);
response.setUrl(url);
response.setObjectName("retrieved information");
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException ipve) {
LOGGER.error("Failed to retrieve diagnostics files from ", ipve);
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage());
} catch (ConfigurationException cre) {
LOGGER.error("Failed to retrieve diagnostics files from ", cre);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.cloud.vm.VirtualMachine;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;

@EntityReference(value = VirtualMachine.class)
public class RetrieveDiagnosticsResponse extends BaseResponse {
@SerializedName(ApiConstants.URL)
@Param(description = "Secondary storage URL were files have been downloaded to")
private String url;


public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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.diagnostics;

import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DataStoreTO;

public class DeleteZipCommand extends Command {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is not custm in cloudstack but can you add some documentation?
i.e:

/**
 * command to clean up after retrieving diagnostics files
 */

private String zipFile;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe name it zipFileName?

private DataStoreTO destStore;

public DeleteZipCommand(DataStoreTO destStore) {
this.zipFile = zipFile;
this.destStore = destStore;
}

@Override
public boolean executeInSequence() {
return false;
}

public DataStoreTO getDestStore() {
return destStore;
}

public String getDiagnosticsZipFile() {
return zipFile;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.diagnostics;

import com.cloud.exception.InvalidParameterValueException;
import com.cloud.utils.component.Manager;
import com.cloud.utils.component.PluggableService;
import org.apache.cloudstack.api.command.admin.diagnostics.RetrieveDiagnosticsCmd;
import org.apache.cloudstack.framework.config.impl.DiagnosticsKey;

import javax.naming.ConfigurationException;
import java.util.List;
import java.util.Map;


public interface RetrieveDiagnosticsService extends Manager, PluggableService {

String getDiagnosticsFiles(final RetrieveDiagnosticsCmd cmd) throws InvalidParameterValueException, ConfigurationException;

boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be in the interface?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Charles, why is this in the interface?


List<DiagnosticsKey> get(String key);
}
7 changes: 6 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@
<artifactId>commons-compress</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-schema</artifactId>
<version>4.12.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
34 changes: 34 additions & 0 deletions core/src/main/java/com/cloud/agent/api/ExecuteScriptCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.cloud.agent.api;

import com.cloud.agent.api.routing.NetworkElementCommand;
import org.apache.log4j.Logger;

public class ExecuteScriptCommand extends NetworkElementCommand {
private static final Logger LOGGER = Logger.getLogger(ExecuteScriptCommand.class);

private String commandScript;
private final boolean executeInSequence;

public ExecuteScriptCommand(String commandScript, boolean executeInSequence) {
this.commandScript = commandScript;
this.executeInSequence = executeInSequence;
}


@Override
public boolean executeInSequence()
{
return this.executeInSequence;
}

@Override
public boolean isQuery() {

return true;
}

public String getCommandScript() {
return commandScript;
}

}
Loading