Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions api/src/main/java/com/cloud/network/as/AutoScaleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public interface AutoScaleService {

Counter createCounter(CreateCounterCmd cmd);

Counter getCounter(long counterId);

boolean deleteCounter(long counterId) throws ResourceInUseException;

List<? extends Counter> listCounters(ListCountersCmd cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.cloudstack.api.command.admin.autoscale;

import org.apache.cloudstack.context.CallContext;

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandResourceType;
Expand Down Expand Up @@ -89,16 +90,18 @@ public void create() {
if (ctr != null) {
this.setEntityId(ctr.getId());
this.setEntityUuid(ctr.getUuid());
CounterResponse response = _responseGenerator.createCounterResponse(ctr);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Counter with name " + getName());
}
}

@Override
public void execute() {
CallContext.current().setEventDetails("Guest OS Id: " + getEntityId());
Counter ctr = _autoScaleService.getCounter(getEntityId());
CounterResponse response = _responseGenerator.createCounterResponse(ctr);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.cloud.utils.db.GenericDao;

public interface CounterDao extends GenericDao<CounterVO, Long> {
CounterVO findByNameProviderValue(String name, String value, String provider);
public List<CounterVO> listCounters(Long id, String name, String source, String provider, String keyword, Filter filter);

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@Component
public class CounterDaoImpl extends GenericDaoBase<CounterVO, Long> implements CounterDao {
final SearchBuilder<CounterVO> AllFieldsSearch;
final SearchBuilder<CounterVO> CounterNameSearch;

protected CounterDaoImpl() {
AllFieldsSearch = createSearchBuilder();
Expand All @@ -40,6 +41,21 @@ protected CounterDaoImpl() {
AllFieldsSearch.and("source", AllFieldsSearch.entity().getSource(), Op.EQ);
AllFieldsSearch.and("provider", AllFieldsSearch.entity().getProvider(), Op.EQ);
AllFieldsSearch.done();

CounterNameSearch = createSearchBuilder();
CounterNameSearch.and("name", CounterNameSearch.entity().getName(), Op.EQ);
CounterNameSearch.and("source", CounterNameSearch.entity().getSource(), Op.EQ);
CounterNameSearch.and("provider", CounterNameSearch.entity().getProvider(), Op.EQ);
CounterNameSearch.done();
}

@Override
public CounterVO findByNameProviderValue(String name, String value, String provider) {
SearchCriteria<CounterVO> sc = CounterNameSearch.create();
sc.setParameters("name", name);
sc.setParameters("value", value);
sc.setParameters("provider", provider);
return findOneBy(sc);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import javax.inject.Inject;

import com.cloud.upgrade.dao.Upgrade42010to42020;
import com.cloud.utils.FileUtil;
import org.apache.cloudstack.utils.CloudStackVersion;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -232,6 +233,7 @@ public DatabaseUpgradeChecker() {
.next("4.19.0.0", new Upgrade41900to41910())
.next("4.19.1.0", new Upgrade41910to42000())
.next("4.20.0.0", new Upgrade42000to42010())
.next("4.20.2.0", new Upgrade42010to42020())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.cloud.upgrade.dao;

import com.cloud.utils.exception.CloudRuntimeException;

import java.io.InputStream;
import java.sql.Connection;

public class Upgrade42010to42020 implements DbUpgrade {
@Override
public String[] getUpgradableVersionRange() {
return new String[]{"4.20.1.0", "4.20.2.0"};
}

@Override
public String getUpgradedVersion() {
return "4.20.2.0";
}

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

@Override
public InputStream[] getPrepareScripts() {
final String scriptFile = "META-INF/db/schema-42010to42020.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);
}

return new InputStream[]{script};
}

@Override
public void performDataMigration(Connection conn) {
}

@Override
public InputStream[] getCleanupScripts() {
final String scriptFile = "META-INF/db/schema-42010to42020-cleanup.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);
}

return new InputStream[]{script};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- 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.

-- in cloud
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_DROP_UNIQUE_KEY`;

CREATE PROCEDURE `cloud`.`IDEMPOTENT_DROP_UNIQUE_KEY` (
IN in_table_name VARCHAR(200),
IN in_index_name VARCHAR(200)
)
BEGIN
DECLARE CONTINUE HANDLER FOR 1091, 1025 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name, ' DROP KEY ', in_index_name); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- 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.

--;
-- Schema cleanup from 4.20.1.0 to 4.20.2.0;
--;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- 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.

--;
-- Schema upgrade from 4.20.1.0 to 4.20.2.0
--;

CALL `cloud`.`IDEMPOTENT_DROP_UNIQUE_KEY`('counter', 'uc_counter__provider__source__value');
CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`('cloud.counter', 'uc_counter__provider__source__value__removed', '(provider, source, value, removed)');
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,7 @@ public AutoScaleVmGroup disableAutoScaleVmGroup(Long id) {
public Counter createCounter(CreateCounterCmd cmd) {
String source = cmd.getSource().toUpperCase();
String name = cmd.getName();
String value = cmd.getValue();
Counter.Source src;
// Validate Source
try {
Expand All @@ -1469,13 +1470,23 @@ public Counter createCounter(CreateCounterCmd cmd) {

CounterVO counter = null;

CounterVO existingCounter = counterDao.findByNameProviderValue(name, value, provider.getName());
if (existingCounter != null) {
throw new InvalidParameterValueException("Counter with name " + name + " already exists");
}
logger.debug("Adding Counter " + name);
counter = counterDao.persist(new CounterVO(src, name, cmd.getValue(), provider));
counter = counterDao.persist(new CounterVO(src, name, value, provider));

CallContext.current().setEventDetails(" Id: " + counter.getId() + " Name: " + name);
return counter;
}

@Override
@ActionEvent(eventType = EventTypes.EVENT_COUNTER_CREATE, eventDescription = "Creating a counter", async = true)
public Counter getCounter(long counterId) {
return counterDao.findById(counterId);
}
Comment on lines +1488 to +1492
Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

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

The getCounter method has incorrect event annotation. It should use EVENT_COUNTER_GET or similar since this is a read operation, not a create operation.

Copilot uses AI. Check for mistakes.

@Override
@ActionEvent(eventType = EventTypes.EVENT_CONDITION_CREATE, eventDescription = "Condition", create = true)
public Condition createCondition(CreateConditionCmd cmd) {
Expand Down
Loading