Retrieve diagnostics (for review purpose)#14
Retrieve diagnostics (for review purpose)#14DaanHoogland wants to merge 72 commits intoshapeblue:masterfrom
Conversation
DaanHoogland
left a comment
There was a problem hiding this comment.
nice concepts you use. I do not see the overall yet, but it looks promissing
| HashMap<DiagnosticsKey.DiagnosticsType, Set<DiagnosticsKey<?>>> _diagnosticsTypeLevelsMap = new HashMap<DiagnosticsKey.DiagnosticsType, Set<DiagnosticsKey<?>>>(); | ||
|
|
||
|
|
||
| \ |
There was a problem hiding this comment.
what happened here? seems syntactically fine but kind of strange formatting
| s_logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName()); | ||
|
|
||
| for (DiagnosticsKey<?> key : configurable..etConfigKeys()) { | ||
| for (DiagnosticsKey<?> key : configurable. . ..get.get.getConfigKeys()) { |
There was a problem hiding this comment.
some artifact that wasn't intended?
|
|
||
|
|
||
|
|
||
| /* public ConfigKey.Scope scope() { |
There was a problem hiding this comment.
code in comment need not be, as we use a versioning system
| import org.apache.cloudstack.framework.config.ConfigDepot; | ||
| import org.apache.cloudstack.framework.config.ConfigDepotAdmin; | ||
| import org.apache.cloudstack.framework.config.impl.ConfigDepotImpl; | ||
| import org.apache.cloudstack.framework.config.ScopedConfigStorage; |
There was a problem hiding this comment.
I cannot find this class. is it checked in?
DaanHoogland
left a comment
There was a problem hiding this comment.
I like how you use the concept of generics. I also see what you are trying to achieve with it. I hope you are not making it to complicated for yourself. We are going to need a lot of unit and integration tests for this to have a clean end result.
| import org.apache.cloudstack.framework.config.ConfigDepot; | ||
| import org.apache.cloudstack.framework.config.ConfigDepotAdmin; | ||
| import org.apache.cloudstack.framework.config.ScopedConfigStorage; | ||
| import org.apache.cloudstack.framework.config.*; |
| @Override | ||
| public <T> void set(ConfigKey<T> key, T value) { | ||
| _configDao.update(key.key(), value.toString()); | ||
| //_diagnosticsDao.update(key.key(), value.toString()); |
| @Override | ||
| public <T> void createOrUpdateConfigObject(String componentName, ConfigKey<T> key, String value) { | ||
| createOrupdateConfigObject(new Date(), componentName, key, value); | ||
| //createOrupdateConfigObject(new Date(), componentName, key, value); |
| public DiagnosticsKey(String role, DiagnosticsEntryType diagnosticstype, String description) { | ||
| _role = role; | ||
| _diagnosticsType = diagnosticstype; | ||
| /* public DiagnosticsKey(Class<T> type, String name, String description) { |
| } | ||
| } | ||
|
|
||
| /* public static DiagnosticsKey<?> getDiagnosticsClassKeys() { |
| //get list of default files from the database table for this diagnostics type | ||
| } else { | ||
| throw new InvalidParameterValueException("Invalid parameters"); | ||
| // System.exit(-1); |
DaanHoogland
left a comment
There was a problem hiding this comment.
the branch still doesn't compile for me.
|
|
||
| public RetrieveDiagnosticsVO(String roleId, String role, String className, String value) { | ||
| this.roleId = roleId; | ||
| /* public RetrieveDiagnosticsVO(String roleId, String role, String className, String value) { |
There was a problem hiding this comment.
no code in comment please
| } | ||
|
|
||
| public void setClassName(String className) { | ||
| public void setDiagnosticsType(String className) { |
|
|
||
| public interface RetrieveDiagnosticsService extends Manager, PluggableService { | ||
|
|
||
| ConfigKey<Long> RetrieveDiagnosticsTimeOut = new ConfigKey<Long>("Advanced", Long.class, "retrieveDiagnostics.retrieval.timeout", "3600", |
There was a problem hiding this comment.
why move to the Impl? isn't it fine here?
| "The interval between garbage collection executions in seconds", true, ConfigKey.Scope.Global); | ||
|
|
||
|
|
||
| /* DiagnosticsKey<String> IPTablesRemove = new DiagnosticsKey<String>(String.class, "IPtables.remove", "The IPtables rules to be removed", null, null); |
There was a problem hiding this comment.
please remove code instead of commenting it out. we have a versioning system to retrieve old code.
35eecfd to
9892e79
Compare
DaanHoogland
left a comment
There was a problem hiding this comment.
I had a new high-level pass on the whole of it. I have two main questions:
- naming in general needs attention. Can we improve on that a bit.
- I want to see why you created the generic. What is your purpose for it?
|
|
||
| RetrieveDiagnosticsResponse getDiagnosticsFiles(final RetrieveDiagnosticsCmd cmd) throws InvalidParameterValueException, ConfigurationException; | ||
|
|
||
| ConfigKey<?>[] getConfigKeys(); |
There was a problem hiding this comment.
this method shouldn't be declared here. It is part of interface Configurable.
There was a problem hiding this comment.
Removed ConfigKey<?> getConfigKeys() from ServiceImpl
There was a problem hiding this comment.
It should remain in the ServiceImpl, @charles-phiri . But it shouldn't be in this interface. It is already defined in Configerable.
| public static final String EVENT_SSVM_STOP = "SSVM.STOP"; | ||
| public static final String EVENT_SSVM_REBOOT = "SSVM.REBOOT"; | ||
| public static final String EVENT_SSVM_HA = "SSVM.HA"; | ||
| public static final String EVENT_SSVM_DIAGNOSTICS = "SSVM.DIAGNOSTICS"; |
There was a problem hiding this comment.
EVENT_SSVM_DIAGNOSTICS is not used outside this file. Do we really need it?
| INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) values (UUID(), 4, 'moveNetworkAclItem', 'ALLOW', 260) ON DUPLICATE KEY UPDATE rule=rule; No newline at end of file | ||
| INSERT INTO `cloud`.`role_permissions` (`uuid`, `role_id`, `rule`, `permission`, `sort_order`) values (UUID(), 4, 'moveNetworkAclItem', 'ALLOW', 260) ON DUPLICATE KEY UPDATE rule=rule; | ||
|
|
||
| CREATE TABLE `cloud`.`diagnosticsdata` ( |
There was a problem hiding this comment.
isn't this more of a 'diagnostics_defaults' or 'diagnostics_configuration'? I don't think the name diagnosticsdata is right for this table.
There was a problem hiding this comment.
I think it is a matter of preference. The name was suggested by Dag....don't know what you think?
There was a problem hiding this comment.
diagnostics data to me suggests that the result of any action or gathering is in this table, as opposed to it containing a means of steering how gathering is done. Hence my two suggestions. I am not religious obout those two, but I think the name diagnosticsdata is misleading.
|
|
||
| private void createOrupdateDiagnosticsObject(String componentName, DiagnosticsKey<?> diagnosticsType) { | ||
| RetrieveDiagnosticsVO vo = _diagnosticsDao.findById(diagnosticsType.key()); | ||
| //DiagnosticsKey diagnosticsKey = new DiagnosticsKey(diagnosticsType.getClass(), diagnosticsType.key(), "new diagnostics") |
|
|
||
| private final static Logger s_logger = Logger.getLogger(DiagnosticsConfigDepotImpl.class); | ||
| @Inject | ||
| RetrieveDiagnosticsDao _diagnosticsDao; |
There was a problem hiding this comment.
we don't need the antiquated convention of prefix '_' on member names.
|
|
||
| } else { | ||
| throw new InvalidParameterValueException("Invalid parameters"); | ||
| // System.exit(-1); |
|
|
||
| public DiagnosticsKey<?>[] getDiagnosticsConfigKeys() | ||
| { | ||
| return null; //new DiagnosticsKey<?>[] { IPTablesRemove, IPTablesRetrieve, LOGFILES, PROPERTYFILES, DNSFILES, DHCPFILES, USERDATA, LB, VPN }; |
| return cmdList; | ||
| } | ||
|
|
||
| /* public SecondaryStorageVmVO startSecondaryStorageVm(long secStorageVmId) { |
| if (fileDetails != null) { | ||
| filesToRetrieve = fileDetails.split(","); | ||
| } else { | ||
| filesToRetrieve = null;//retrieve default files from db |
There was a problem hiding this comment.
is this comment a TODO?
| 'cloudian': 'Cloudian', | ||
| 'Sioc' : 'Sioc' | ||
| 'Sioc' : 'Sioc', | ||
| 'retrieveDiagnostics': 'System VM' |
There was a problem hiding this comment.
is this the right tag/token? it seems to me that it deserves its own class. It will also be applicable to hosts in the future (maybe)
There was a problem hiding this comment.
From the documentation, it looks to me like it is the right file.
There was a problem hiding this comment.
yes, it is the right file. I wonder about the value of the tag, not the place it is defined
DaanHoogland
left a comment
There was a problem hiding this comment.
so far, now.
pleae push further changes asap.
| @@ -0,0 +1,59 @@ | |||
| /* | |||
| * // Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
please remove the nested comment
| * // under the License. | ||
| */ | ||
|
|
||
| // Licensed to the Apache Software Foundation (ASF) under one |
There was a problem hiding this comment.
three licenses is a bit overdone
| @@ -0,0 +1,90 @@ | |||
| /* | |||
| * // Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
same issue as in answer
|
|
||
| public RetrieveDiagnosticsService getRetrieveDiagnosticsService() { | ||
| return retrieveDiagnosticsService; | ||
| public static Logger getS_logger() { |
There was a problem hiding this comment.
why an accessor for the logger? it is only used locally isn't it?
There was a problem hiding this comment.
also it should be called LOGGER or LOG as it is static final. and not have the obsoleted 's_' prefix
|
|
||
| public void setRetrieveDiagnosticsService(RetrieveDiagnosticsService retrieveDiagnosticsService) { | ||
| this.retrieveDiagnosticsService = retrieveDiagnosticsService; | ||
| public static String getAPINAME() { |
There was a problem hiding this comment.
this is not to be accessed outside the class is it?
| INSERT INTO `cloud`.`diagnosticsdata` (`role`, `class`, `value`) values ('VR', 'VPN', '<vpn configuration file>'); | ||
| INSERT INTO `cloud`.`diagnosticsdata` (`role`, `class`, `value`) values ('VR', 'LOGFILES', 'cloud.log,agent.log'); | ||
| INSERT INTO `cloud`.`diagnosticsdata` (`role`, `class`, `value`) values ('CPVM', 'PROPERTYFILES', '<CPVM property file>'); | ||
| INSERT INTO `cloud`.`diagnosticsdata` (`role`, `class`, `value`) values ('SecondaryStorageVm', 'LOGFILES', 'cloud.log,agent.log,[IPTABLES]'); |
| @@ -0,0 +1,38 @@ | |||
| /* | |||
There was a problem hiding this comment.
can you remove the nesting in the comment, please?
There was a problem hiding this comment.
no, it is still here
There was a problem hiding this comment.
I have changed it. Will make a push soon after completing the code I am working on.
| @@ -0,0 +1,62 @@ | |||
| /* | |||
| * // Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
please remove the nesting in the comment.
There was a problem hiding this comment.
but you didn't commit it?
| private Date lastSent; | ||
|
|
||
| @SerializedName(ApiConstants.TIMEOUT) | ||
| @Param(description = "the timeout (in seconds) for requests to the retrieve diagnostics API") |
There was a problem hiding this comment.
what is the purpose of this in the response? i.e. what information does the user get from this response field?
| entityEventDetails.put(EVENT_SSVM_STOP, VirtualMachine.class); | ||
| entityEventDetails.put(EVENT_SSVM_REBOOT, VirtualMachine.class); | ||
| entityEventDetails.put(EVENT_SSVM_HA, VirtualMachine.class); | ||
| entityEventDetails.put(EVENT_SSVM_DIAGNOSTICS, VirtualMachine.class); |
There was a problem hiding this comment.
Removed it but I think we might need Events at a later stage.
| RetrieveDiagnosticsResponse retrieveDiagnosticsResponse = new RetrieveDiagnosticsResponse(); | ||
| try { | ||
| retrieveDiagnosticsService.getDiagnosticsFiles(this); | ||
| retrieveDiagnosticsResponse.setObjectName("retrievediagnostics"); |
There was a problem hiding this comment.
is this the ideal object name? did you have other names considdered?
There was a problem hiding this comment.
"diagnostics" maybe? or retrievedlogs, diagnosticsinformation. diagnosticdata.
I am really not sure it is a sincere question. It is just that retrievediagnostics (which is a spelling error btw, only one d) does not seem right.
from wiktionary: diagnostics
plural of diagnostic
The process of determining the state of or capability of a component to perform its function(s).
retrieving a process is not intuitively right.
There was a problem hiding this comment.
I think diagnosticsinformation makes sense. Do you want me to change the whole class or just retrieveDiagnosticsResponse.setObjectName("retrievediagnostics");
|
|
||
| @Override | ||
| public String getEventDescription() { | ||
| return "Retrieved diagnostics files from System VM =" + id; |
There was a problem hiding this comment.
"System VM =" may be too specific if we add hosts or hardware loadbalancers. We might go for "host: ". What do you think?
| // under the License. | ||
| package org.apache.cloudstack.api.command.admin.systemvm; | ||
|
|
||
| import org.apache.log4j.Logger; |
There was a problem hiding this comment.
there is only imports chaged in this file. consider reverting it.
| } | ||
|
|
||
| @Override | ||
| public boolean isQuery() { |
There was a problem hiding this comment.
please look at the formatting here
| @Component | ||
| public class RetrieveDiagnosticsDaoImpl extends GenericDaoBase<RetrieveDiagnosticsVO, String> implements RetrieveDiagnosticsDao | ||
| { | ||
| private final SearchBuilder<RetrieveDiagnosticsVO> DiagnosticsSearchByType; |
There was a problem hiding this comment.
can you check if we need this, please. it is not used in the class or in its interface. I think you blindly copied my code from annotations and I should have removed it there myself. I am not sure, though.
| import java.util.HashMap; | ||
| import java.util.List; | ||
|
|
||
| public class DiagnosticsConfigDepotImpl implements DiagnosticsConfigDepot { |
There was a problem hiding this comment.
The name depot is not very fortunate. Please help think of a better one. I am thinking of just DiagnosticsConfiguration or DiagnosticsConfigurator.
|
|
||
| public class DiagnosticsConfigDepotImpl implements DiagnosticsConfigDepot { | ||
|
|
||
| private final static Logger s_logger = Logger.getLogger(DiagnosticsConfigDepotImpl.class); |
There was a problem hiding this comment.
the naming convention of s_ is obsolete, please use the name for a static final in all uppercase; i.e. LOG or LOGGER
There was a problem hiding this comment.
Done. Will have to look at other classes and change as required.
| import java.util.HashMap; | ||
| import java.util.List; | ||
|
|
||
| public interface DiagnosticsConfigDepot { |
There was a problem hiding this comment.
naming is a bit off. please see the -Impl for discussion
There was a problem hiding this comment.
We have to discuss this so that I can learn the naming conversion. Meanwhile, I will leave it as it is.
There was a problem hiding this comment.
I think you mean convention, right? I am not sure there is a convention for what you are trying to do here yet. That would mean we are free to choose. Of course with that freedom comes great responsibility ;) I must be intuitively right.
| @Parameter(name = ApiConstants.ID, | ||
| type = CommandType.UUID, | ||
| entityType = RetrieveDiagnosticsResponse.class, | ||
| entityType = DomainRouterResponse.class, |
There was a problem hiding this comment.
So this call is now only valid for DomainRouters? using the DomainRouterResponse.class...? I think something went wrong here
| public class RetrieveDiagnosticsDaoImpl extends GenericDaoBase<RetrieveDiagnosticsVO, String> implements RetrieveDiagnosticsDao | ||
| { | ||
| private final SearchBuilder<RetrieveDiagnosticsVO> DiagnosticsSearchByType; | ||
| // private final SearchBuilder<RetrieveDiagnosticsVO> DiagnosticsSearchByType; |
There was a problem hiding this comment.
did it work, without? (just remove, git will find it back if you need it;)
| @@ -0,0 +1,24 @@ | |||
|
|
|||
| /* | |||
| * // Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
this is still nested comment
borisstoyanov
left a comment
There was a problem hiding this comment.
Can we also add a marvin test?
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
is there any reason we need that many empty lines?
|
|
||
| protected Answer copyFileFromSystemVm(final NetworkElementCommand cmd, String script) throws Exception { | ||
| final File keyFile = getSystemVMKeyFile(); | ||
| private CreateEntityDownloadURLAnswer downloadCompressedFileToSSVM(CreateEntityDownloadURLCommand cmd, final String diagnosticsZipFileName) { |
There was a problem hiding this comment.
can you break this up in smaller methods?
i.e. checkApache(), mkdirCommand(), linkCommand() etc...
| private String secUrl; | ||
|
|
||
| @Inject | ||
| NetworkModel _networkModel; |
There was a problem hiding this comment.
please remove the underscore from the name
| NetworkModel _networkModel; | ||
|
|
||
| @Inject | ||
| NetworkDao _networksDao = null; |
There was a problem hiding this comment.
please remove the underscore from the name
| NetworkDao _networksDao = null; | ||
|
|
||
| @Inject | ||
| NicDao _nicDao = null; |
There was a problem hiding this comment.
please remove the underscore from the name
| NicDao _nicDao = null; | ||
|
|
||
| @Inject | ||
| private HostDao _hostDao; |
There was a problem hiding this comment.
please remove the underscore from the names, here and below
| private VirtualMachineManager vmManager; | ||
|
|
||
| @Inject | ||
| protected DataCenterDao _dcDao = null; |
There was a problem hiding this comment.
please remove the underscore from the name
| protected DataCenterDao _dcDao = null; | ||
|
|
||
| @Inject | ||
| protected PrimaryDataStoreDao _storagePoolDao = null; |
There was a problem hiding this comment.
please remove the underscore from the name
| } | ||
| final Long vmId = cmd.getId(); | ||
| vmInstance = _vmDao.findByIdTypes(vmId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.DomainRouter, VirtualMachine.Type.SecondaryStorageVm); | ||
| //vmInstance.getDetails() |
There was a problem hiding this comment.
please remove code in comment
| @@ -0,0 +1,52 @@ | |||
| /* | |||
| * // Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
this is a nested comment, please use either /* */ or //
| @@ -0,0 +1,29 @@ | |||
| /* | |||
| * // Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
please remove nested comment
| NicDao _nicDao = null; | ||
|
|
||
| @Inject | ||
| private HostDao _hostDao; |
There was a problem hiding this comment.
please remove the _ from this field and all those below
| filesToRetrieve.add(files[i]); | ||
| } | ||
| } | ||
| // ManagementServerHostVO managementServerHostVO = managementServerHostDao.findById(systemVmId..getHostId()); |
There was a problem hiding this comment.
remove commented code
| } | ||
| } | ||
| // ManagementServerHostVO managementServerHostVO = managementServerHostDao.findById(systemVmId..getHostId()); | ||
| //String ipHostAddress = managementServerHostVO.getServiceIP(); |
There was a problem hiding this comment.
remove commented code
| RetrieveFilesCommand retrieveFilesCommand = null; | ||
| Map<String, String> resultsMap; | ||
| final Long hostId = systemVmId.getHostId(); | ||
| //Answer answer = null; |
There was a problem hiding this comment.
remove commented code
| if (store == null) { | ||
| throw new CloudRuntimeException("cannot find an image store for zone " + zoneId); | ||
| } | ||
| //DataStoreTO destStoreTO = store.getTO(); |
There was a problem hiding this comment.
remove commented code
| @@ -0,0 +1,228 @@ | |||
| /* | |||
| * // Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
remove nested comments
|
|
||
| } | ||
|
|
||
| Map<String, String> resultsMap = new HashMap<>();//retrieveDiagnosticsService.getDiagnosticsFiles(retrieveDiagnosticsCmd); |
There was a problem hiding this comment.
remove the commented code at the end of this line
| except OSError as e: | ||
| print("Failed to create directory temp") | ||
|
|
||
| #manifest_file = open("temp/" + "manifest.txt", "w+") |
There was a problem hiding this comment.
remove commented code
| print filename + " not found" | ||
| #manifest_file.write(filename + " not found.") | ||
|
|
||
| #zip_archive.write(manifest_file) |
There was a problem hiding this comment.
remove commented code
| #manifest_file.write(filename + " not found.") | ||
|
|
||
| #zip_archive.write(manifest_file) | ||
| #manifest_file.close() |
There was a problem hiding this comment.
remove commented code
| save_files = SaveIptablesToLogFile(arguments) | ||
| save_files.ensure_dir(file_path) | ||
| save_files.saveIpTableEntries(file_path) | ||
|
|
There was a problem hiding this comment.
too many extra lines
|
@charles-phiri please rebase to resolve conflicts and make sure the build passes |
No description provided.