Skip to content

[WIP] feature: access logs in ui #10758

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -90,6 +90,7 @@ public class ApiConstants {
public static final String CONVERT_INSTANCE_HOST_ID = "convertinstancehostid";
public static final String CONVERT_INSTANCE_STORAGE_POOL_ID = "convertinstancepoolid";
public static final String ENABLED_REVOCATION_CHECK = "enabledrevocationcheck";
public static final String CONTEXT_ID = "contextid";
public static final String CONTROLLER = "controller";
public static final String CONTROLLER_UNIT = "controllerunit";
public static final String COPY_IMAGE_TAGS = "copyimagetags";
Expand Down Expand Up @@ -119,12 +120,15 @@ public class ApiConstants {
public static final String CN = "cn";
public static final String COMMAND = "command";
public static final String CMD_EVENT_TYPE = "cmdeventtype";
public static final String CLIENT_ADDRESS = "clientaddress";
public static final String COMPONENT = "component";
public static final String CONNECTED = "connected";
public static final String CPU_CORE_PER_SOCKET = "cpucorepersocket";
public static final String CPU_NUMBER = "cpunumber";
public static final String CPU_SPEED = "cpuspeed";
public static final String CPU_LOAD_AVERAGE = "cpuloadaverage";
public static final String CREATED = "created";
public static final String CREATOR_ADDRESS = "creatoraddress";
public static final String CTX_ACCOUNT_ID = "ctxaccountid";
public static final String CTX_DETAILS = "ctxDetails";
public static final String CTX_USER_ID = "ctxuserid";
Expand All @@ -140,6 +144,7 @@ public class ApiConstants {
public static final String ENCRYPT_FORMAT = "encryptformat";
public static final String ENCRYPT_ROOT = "encryptroot";
public static final String ENCRYPTION_SUPPORTED = "encryptionsupported";
public static final String FILTERS = "filters";
public static final String MIN_IOPS = "miniops";
public static final String MAX_IOPS = "maxiops";
public static final String HYPERVISOR_SNAPSHOT_RESERVE = "hypervisorsnapshotreserve";
Expand Down Expand Up @@ -1191,6 +1196,8 @@ public class ApiConstants {
public static final String WEBHOOK_ID = "webhookid";
public static final String WEBHOOK_NAME = "webhookname";

public static final String WEBSOCKET = "websocket";

public static final String NFS_MOUNT_OPTIONS = "nfsmountopts";
public static final String MOUNT_OPTIONS = "mountopts";

Expand All @@ -1207,6 +1214,8 @@ public class ApiConstants {
public static final String OBJECT_STORAGE_LIMIT = "objectstoragelimit";
public static final String OBJECT_STORAGE_TOTAL = "objectstoragetotal";

public static final String LOGS_WEB_SERVER_ENABLED = "logswebserverenabled";

public static final String PARAMETER_DESCRIPTION_ACTIVATION_RULE = "Quota tariff's activation rule. It can receive a JS script that results in either " +
"a boolean or a numeric value: if it results in a boolean value, the tariff value will be applied according to the result; if it results in a numeric value, the " +
"numeric value will be applied; if the result is neither a boolean nor a numeric value, the tariff will not be applied. If the rule is not informed, the tariff " +
Expand Down
14 changes: 14 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/BaseResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
@Param(description = "the current status of the latest async job acting on this object")
private Integer jobStatus;

@SerializedName(ApiConstants.CONTEXT_ID)
@Param(description = "the ID of the executing context")
private String contextId;

public BaseResponse() {
}

Expand Down Expand Up @@ -83,4 +87,14 @@
public void setJobStatus(Integer jobStatus) {
this.jobStatus = jobStatus;
}

@Override
public String getContextId() {
return contextId;
}

Check warning on line 94 in api/src/main/java/org/apache/cloudstack/api/BaseResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/BaseResponse.java#L92-L94

Added lines #L92 - L94 were not covered by tests

@Override
public void setContextId(String contextId) {
this.contextId = contextId;
}

Check warning on line 99 in api/src/main/java/org/apache/cloudstack/api/BaseResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/BaseResponse.java#L97-L99

Added lines #L97 - L99 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public interface ResponseObject {
*/
void setJobStatus(Integer jobStatus);

String getContextId();
void setContextId(String contextId);

public enum ResponseView {
Full,
Restricted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.commons.lang3.StringUtils;

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.ManagementServerResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.config.Configuration;
import org.apache.commons.lang3.StringUtils;

import com.cloud.exception.InvalidParameterValueException;
import com.cloud.utils.Pair;
Expand Down Expand Up @@ -94,6 +94,13 @@
description = "the ID of the Image Store to update the parameter value for corresponding image store")
private Long imageStoreId;

@Parameter(name = ApiConstants.MANAGEMENT_SERVER_ID,
type = CommandType.UUID,
entityType = ManagementServerResponse.class,
description = "the ID of the Management Server to update the parameter value for corresponding management server",
since = "4.21.0")
private Long managementServerId;

@Parameter(name = ApiConstants.GROUP, type = CommandType.STRING, description = "lists configuration by group name (primarily used for UI)", since = "4.18.0")
private String groupName;

Expand Down Expand Up @@ -139,6 +146,10 @@
return imageStoreId;
}

public Long getManagementServerId() {
return managementServerId;
}

public String getGroupName() {
return groupName;
}
Expand Down Expand Up @@ -200,6 +211,9 @@
if (getImageStoreId() != null){
cfgResponse.setScope("imagestore");
}
if (getManagementServerId() != null){
cfgResponse.setScope("managementserver");

Check warning on line 215 in api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java#L215

Added line #L215 was not covered by tests
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.framework.config.ConfigKey;

import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ManagementServerResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.framework.config.ConfigKey;

import com.cloud.user.Account;
import com.cloud.utils.Pair;
Expand Down Expand Up @@ -84,6 +84,13 @@
description = "the ID of the Image Store to reset the parameter value for corresponding image store")
private Long imageStoreId;

@Parameter(name = ApiConstants.MANAGEMENT_SERVER_ID,
type = CommandType.UUID,
entityType = ManagementServerResponse.class,
description = "the ID of the Management Server to update the parameter value for corresponding management server",
since = "4.21.0")
private Long managementServerId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -116,6 +123,10 @@
return imageStoreId;
}

public Long getManagementServerId() {

Check warning on line 126 in api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java#L126

Added line #L126 was not covered by tests
return managementServerId;
}

Check warning on line 128 in api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java#L128

Added line #L128 was not covered by tests

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -149,6 +160,9 @@
if (getImageStoreId() != null) {
response.setScope(ConfigKey.Scope.ImageStore.name());
}
if (getManagementServerId() != null) {
response.setScope(ConfigKey.Scope.ManagementServer.name());

Check warning on line 164 in api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java#L164

Added line #L164 was not covered by tests
}
response.setValue(cfg.second());
this.setResponseObject(response);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ManagementServerResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.config.Configuration;
Expand Down Expand Up @@ -88,6 +89,14 @@
validations = ApiArgValidator.PositiveNumber)
private Long imageStoreId;

@Parameter(name = ApiConstants.MANAGEMENT_SERVER_ID,
type = CommandType.UUID,
entityType = ManagementServerResponse.class,
description = "the ID of the Management Server to update the parameter value for corresponding management server",
validations = ApiArgValidator.PositiveNumber,
since = "4.21.0")
private Long managementServerId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -112,7 +121,7 @@
return clusterId;
}

public Long getStoragepoolId() {
public Long getStoragePoolId() {
return storagePoolId;
}

Expand All @@ -128,6 +137,10 @@
return imageStoreId;
}

public Long getManagementServerId() {
return managementServerId;
}

Check warning on line 142 in api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java#L140-L142

Added lines #L140 - L142 were not covered by tests

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -184,7 +197,7 @@
if (getClusterId() != null) {
response.setScope("cluster");
}
if (getStoragepoolId() != null) {
if (getStoragePoolId() != null) {
response.setScope("storagepool");
}
if (getAccountId() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
response.setInstancesDisksStatsRetentionTime((Integer) capabilities.get(ApiConstants.INSTANCES_DISKS_STATS_RETENTION_TIME));
response.setSharedFsVmMinCpuCount((Integer)capabilities.get(ApiConstants.SHAREDFSVM_MIN_CPU_COUNT));
response.setSharedFsVmMinRamSize((Integer)capabilities.get(ApiConstants.SHAREDFSVM_MIN_RAM_SIZE));
response.setLogsWebServerEnabled((Boolean)capabilities.get(ApiConstants.LOGS_WEB_SERVER_ENABLED));

Check warning on line 75 in api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java#L75

Added line #L75 was not covered by tests
response.setObjectName("capability");
response.setResponseName(getCommandName());
this.setResponseObject(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
@Param(description = "the min Ram size for the service offering used by the shared filesystem instance", since = "4.20.0")
private Integer sharedFsVmMinRamSize;

@SerializedName(ApiConstants.LOGS_WEB_SERVER_ENABLED)
@Param(description = "true if Logs Web Server plugin is enabled, false otherwise", since = "4.21.0")
private boolean logsWebServerEnabled;

public void setSecurityGroupsEnabled(boolean securityGroupsEnabled) {
this.securityGroupsEnabled = securityGroupsEnabled;
}
Expand Down Expand Up @@ -247,4 +251,8 @@
public void setSharedFsVmMinRamSize(Integer sharedFsVmMinRamSize) {
this.sharedFsVmMinRamSize = sharedFsVmMinRamSize;
}

public void setLogsWebServerEnabled(boolean logsWebServerEnabled) {
this.logsWebServerEnabled = logsWebServerEnabled;
}

Check warning on line 257 in api/src/main/java/org/apache/cloudstack/api/response/CapabilitiesResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/response/CapabilitiesResponse.java#L255-L257

Added lines #L255 - L257 were not covered by tests
}
5 changes: 5 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@
<artifactId>cloud-plugin-user-two-factor-authenticator-staticpin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-logs-web-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-plugin-metrics</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.io.IOException;
import java.util.List;

@Converter
public class StringListJsonConverter implements AttributeConverter<List<String>, String> {

private static final ObjectMapper mapper = new ObjectMapper();

Check warning on line 30 in engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java#L30

Added line #L30 was not covered by tests

@Override
public String convertToDatabaseColumn(List<String> attribute) {
try {

Check warning on line 34 in engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java#L33-L34

Added lines #L33 - L34 were not covered by tests
return attribute == null ? null : mapper.writeValueAsString(attribute);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Error converting list to JSON", e);

Check warning on line 37 in engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java#L36-L37

Added lines #L36 - L37 were not covered by tests
}
}

Check warning on line 39 in engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java#L39

Added line #L39 was not covered by tests

@Override
public List<String> convertToEntityAttribute(String dbData) {
try {

Check warning on line 43 in engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java#L42-L43

Added lines #L42 - L43 were not covered by tests
return dbData == null ? null : mapper.readValue(dbData, List.class);
} catch (IOException e) {
throw new IllegalArgumentException("Error converting JSON to list", e);

Check warning on line 46 in engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java#L45-L46

Added lines #L45 - L46 were not covered by tests
}
}

Check warning on line 48 in engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/org/apache/cloudstack/util/StringListJsonConverter.java#L48

Added line #L48 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<bean id="loadBalancerVMMapDaoImpl" class="com.cloud.network.dao.LoadBalancerVMMapDaoImpl" />
<bean id="loadBalancerCertMapDaoImpl" class="com.cloud.network.dao.LoadBalancerCertMapDaoImpl" />
<bean id="managementServerHostDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostDaoImpl" />
<bean id="managementServerHostDetailsDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostDetailsDaoImpl" />
<bean id="managementServerHostPeerDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostPeerDaoImpl" />
<bean id="managementServerHostPeerJoinDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostPeerJoinDaoImpl" />
<bean id="managementServerStatusDaoImpl" class="com.cloud.cluster.dao.ManagementServerStatusDaoImpl" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
--;
-- Schema upgrade cleanup from 4.20.1.0 to 4.21.0.0
--;

DROP TABLE IF EXISTS `cloud`.`logs_web_session`;
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,29 @@ WHERE rp.rule = 'quotaStatement'
AND NOT EXISTS(SELECT 1 FROM cloud.role_permissions rp_ WHERE rp.role_id = rp_.role_id AND rp_.rule = 'quotaCreditsList');

CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.host', 'last_mgmt_server_id', 'bigint unsigned DEFAULT NULL COMMENT "last management server this host is connected to" AFTER `mgmt_server_id`');

CREATE TABLE IF NOT EXISTS `management_server_details` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`management_server_id` bigint unsigned NOT NULL COMMENT 'management server the detail is related to',
`name` varchar(255) NOT NULL COMMENT 'name of the detail',
`value` varchar(255) NOT NULL,
`display` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'True if the detail can be displayed to the end user',
PRIMARY KEY (`id`),
CONSTRAINT `fk_management_server_details__management_server_id` FOREIGN KEY `fk_management_server_details__management_server_id`(`management_server_id`) REFERENCES `mshost`(`id`) ON DELETE CASCADE,
KEY `i_management_server_details__name__value` (`name`(128),`value`(128))
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `cloud`.`logs_web_session` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
`uuid` varchar(40) NOT NULL COMMENT 'UUID generated for the session',
`filter` varchar(64) DEFAULT NULL COMMENT 'Filter keyword for the session',
`created` datetime NOT NULL COMMENT 'When the session was created',
`domain_id` bigint(20) unsigned NOT NULL COMMENT 'Domain of the account who generated the session',
`account_id` bigint(20) unsigned NOT NULL COMMENT 'Account who generated the session',
`creator_address` VARCHAR(45) DEFAULT NULL COMMENT 'Address of the creator of the session',
`connections` int unsigned NOT NULL DEFAULT 0 COMMENT 'Number of connections for the session',
`connected_time` datetime DEFAULT NULL COMMENT 'When the session was connected',
`client_address` VARCHAR(45) DEFAULT NULL COMMENT 'Address of the client that connected to the session',
`removed` datetime COMMENT 'When the session was removed/used',
CONSTRAINT `uc_logs_web_session__uuid` UNIQUE (`uuid`)
);
Loading
Loading