-
Notifications
You must be signed in to change notification settings - Fork 6
Retrieve diagnostics (for review purpose) #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1ee9980
9f7eff1
987534e
4ef4c2f
6256e91
c7e5572
74822ce
e017c1c
9438236
99bb448
3cdb059
be2d1b3
6c76aa9
1e24faa
ee7907c
65b7d38
182dea9
395b246
aae408c
a4c6d5d
e8aa68b
a10c798
e0292b5
64a6185
135383d
2be2e9d
943626e
e187bc1
98e2aa5
3b97954
987b6f7
2ff8287
351f721
94a2fb5
8b57ee6
8995e4f
e6c1029
974de4a
fc5ef6f
ca4dd82
ca5c308
fa129fa
e97895f
f525aa9
3e62161
cc880d4
91514d4
141ab51
2e55ec2
d2b2d62
45bd812
c9d7ad2
dd5579d
46098bc
5d22c03
5086e34
555cc86
94b414d
0f19d46
956a434
76e5545
c458261
9a6c5cf
24f123a
f66c840
1e4a426
63f6b9b
3acbfe4
d08cc7b
3c12e07
f88bde0
720da4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
private String zipFile; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be in the interface? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Charles, why is this in the interface? |
||
|
||
List<DiagnosticsKey> get(String key); | ||
} |
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; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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: