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

ResourceGroup interfaces for V2 #1256

Merged
merged 1 commit into from
Dec 27, 2024
Merged
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
31 changes: 31 additions & 0 deletions src/main/java/io/milvus/common/resourcegroup/NodeInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 io.milvus.common.resourcegroup;

import lombok.Data;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
public class NodeInfo {
private Long nodeId;
private String address;
private String hostname;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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 io.milvus.common.resourcegroup;

import java.util.stream.Collectors;
Expand All @@ -12,10 +31,12 @@ public class ResourceGroupConfig {
private final ResourceGroupLimit limits;
private final List<ResourceGroupTransfer> from;
private final List<ResourceGroupTransfer> to;
private final ResourceGroupNodeFilter nodeFilter;

private ResourceGroupConfig(Builder builder) {
this.requests = builder.requests;
this.limits = builder.limits;
this.nodeFilter = builder.nodeFilter;

if (null == builder.from) {
this.from = new ArrayList<>();
Expand All @@ -39,6 +60,7 @@ public static final class Builder {
private ResourceGroupLimit limits;
private List<ResourceGroupTransfer> from;
private List<ResourceGroupTransfer> to;
private ResourceGroupNodeFilter nodeFilter;

private Builder() {
}
Expand Down Expand Up @@ -87,6 +109,17 @@ public Builder withTo(@NonNull List<ResourceGroupTransfer> to) {
return this;
}

/**
* Set the node filter.
* @param nodeFilter if node filter set, resource group will prefer to accept node which match node filter.
* @return <code>Builder</code>
*/

public Builder withNodeFilter(@NonNull ResourceGroupNodeFilter nodeFilter) {
this.nodeFilter = nodeFilter;
return this;
}

public ResourceGroupConfig build() {
return new ResourceGroupConfig(this);
}
Expand All @@ -101,12 +134,14 @@ public ResourceGroupConfig(@NonNull io.milvus.grpc.ResourceGroupConfig grpcConfi
this.to = grpcConfig.getTransferToList().stream()
.map(transfer -> new ResourceGroupTransfer(transfer))
.collect(Collectors.toList());
this.nodeFilter = new ResourceGroupNodeFilter(grpcConfig.getNodeFilter());
}

public @NonNull io.milvus.grpc.ResourceGroupConfig toGRPC() {
io.milvus.grpc.ResourceGroupConfig.Builder builder = io.milvus.grpc.ResourceGroupConfig.newBuilder()
.setRequests(io.milvus.grpc.ResourceGroupLimit.newBuilder().setNodeNum(requests.getNodeNum()))
.setLimits(io.milvus.grpc.ResourceGroupLimit.newBuilder().setNodeNum(limits.getNodeNum()));
.setLimits(io.milvus.grpc.ResourceGroupLimit.newBuilder().setNodeNum(limits.getNodeNum()))
.setNodeFilter(nodeFilter.toGRPC());
for (ResourceGroupTransfer transfer : from) {
builder.addTransferFrom(transfer.toGRPC());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
package io.milvus.common.resourcegroup;
/*
* 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.
*/

import org.jetbrains.annotations.NotNull;
package io.milvus.common.resourcegroup;

import lombok.Getter;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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 io.milvus.common.resourcegroup;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import io.milvus.grpc.KeyValuePair;
import io.milvus.param.ParamUtils;
import lombok.Getter;
import lombok.NonNull;

@Getter
public class ResourceGroupNodeFilter {
private final Map<String, String> nodeLabels;

private ResourceGroupNodeFilter(Builder builder) {
this.nodeLabels = builder.nodeLabels;
}

public static Builder newBuilder() {
return new Builder();
}

public static final class Builder {
private Map<String, String> nodeLabels = new HashMap<>();
private Builder() {
}

/**
* Set the node label filter
* @param key label name
* @param value label value
* @return <code>Builder</code>
*/
public Builder withNodeLabel(@NonNull String key, @NonNull String value) {
this.nodeLabels.put(key, value);
return this;
}

public ResourceGroupNodeFilter build() {
return new ResourceGroupNodeFilter(this);
}
}

/**
* Transfer to grpc
* @return io.milvus.grpc.ResourceGroupNodeFilter
*/
public @NonNull io.milvus.grpc.ResourceGroupNodeFilter toGRPC() {
List<KeyValuePair> pair = ParamUtils.AssembleKvPair(nodeLabels);
return io.milvus.grpc.ResourceGroupNodeFilter.newBuilder()
.addAllNodeLabels(pair)
.build();
}

/**
* Constructor from grpc
* @param filter grpc filter object
*/
public ResourceGroupNodeFilter(io.milvus.grpc.ResourceGroupNodeFilter filter) {
this.nodeLabels = filter.getNodeLabelsList().stream().collect(Collectors.toMap(KeyValuePair::getKey, KeyValuePair::getValue));
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/*
* 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 io.milvus.common.resourcegroup;

import lombok.Getter;
Expand Down
Loading
Loading