Skip to content
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

Allow counters to be created with same name, provider and source as a deleted one #10223

Open
wants to merge 6 commits into
base: 4.19
Choose a base branch
from
Open
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
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.log4j.Logger;

import org.apache.cloudstack.api.APICommand;
Expand Down Expand Up @@ -91,16 +92,18 @@
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);

Check warning on line 106 in api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java#L102-L106

Added lines #L102 - L106 were not covered by tests
}

@Override
Expand Down
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
Expand Up @@ -22,6 +22,9 @@
-- Add last_id to the volumes table
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes', 'last_id', 'bigint(20) unsigned DEFAULT NULL');

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)');

-- Grant access to 2FA APIs for the "Read-Only User - Default" role

CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Read-Only User - Default', 'setupUserTwoFactorAuthentication', 'ALLOW');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,12 @@
return counter;
}

@Override
@ActionEvent(eventType = EventTypes.EVENT_COUNTER_CREATE, eventDescription = "Creating a counter", async = true)
public Counter getCounter(long counterId) {
return counterDao.findById(counterId);
}

Check warning on line 1481 in server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java#L1479-L1481

Added lines #L1479 - L1481 were not covered by tests

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