Github user knusbaum commented on a diff in the pull request:

    https://github.com/apache/storm/pull/1053#discussion_r52064259
  
    --- Diff: 
storm-core/src/jvm/org/apache/storm/container/cgroup/core/BlkioCore.java ---
    @@ -0,0 +1,259 @@
    +/**
    + * 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.storm.container.cgroup.core;
    +
    +import org.apache.storm.container.cgroup.CgroupUtils;
    +import org.apache.storm.container.cgroup.Constants;
    +import org.apache.storm.container.cgroup.SubSystemType;
    +import org.apache.storm.container.cgroup.Device;
    +
    +import java.io.IOException;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +
    +public class BlkioCore implements CgroupCore {
    +
    +    public static final String BLKIO_WEIGHT = "/blkio.weight";
    +    public static final String BLKIO_WEIGHT_DEVICE = 
"/blkio.weight_device";
    +    public static final String BLKIO_RESET_STATS = "/blkio.reset_stats";
    +
    +    public static final String BLKIO_THROTTLE_READ_BPS_DEVICE = 
"/blkio.throttle.read_bps_device";
    +    public static final String BLKIO_THROTTLE_WRITE_BPS_DEVICE = 
"/blkio.throttle.write_bps_device";
    +    public static final String BLKIO_THROTTLE_READ_IOPS_DEVICE = 
"/blkio.throttle.read_iops_device";
    +    public static final String BLKIO_THROTTLE_WRITE_IOPS_DEVICE = 
"/blkio.throttle.write_iops_device";
    +
    +    public static final String BLKIO_THROTTLE_IO_SERVICED = 
"/blkio.throttle.io_serviced";
    +    public static final String BLKIO_THROTTLE_IO_SERVICE_BYTES = 
"/blkio.throttle.io_service_bytes";
    +
    +    public static final String BLKIO_TIME = "/blkio.time";
    +    public static final String BLKIO_SECTORS = "/blkio.sectors";
    +    public static final String BLKIO_IO_SERVICED = "/blkio.io_serviced";
    +    public static final String BLKIO_IO_SERVICE_BYTES = 
"/blkio.io_service_bytes";
    +    public static final String BLKIO_IO_SERVICE_TIME = 
"/blkio.io_service_time";
    +    public static final String BLKIO_IO_WAIT_TIME = "/blkio.io_wait_time";
    +    public static final String BLKIO_IO_MERGED = "/blkio.io_merged";
    +    public static final String BLKIO_IO_QUEUED = "/blkio.io_queued";
    +
    +    private final String dir;
    +
    +    public BlkioCore(String dir) {
    +        this.dir = dir;
    +    }
    +
    +    @Override
    +    public SubSystemType getType() {
    +        return SubSystemType.blkio;
    +    }
    +
    +    /* weight: 100-1000 */
    +    public void setBlkioWeight(int weight) throws IOException {
    +        CgroupUtils.writeFileByLine(Constants.getDir(this.dir, 
BLKIO_WEIGHT), String.valueOf(weight));
    +    }
    +
    +    public int getBlkioWeight() throws IOException {
    +        return 
Integer.valueOf(CgroupUtils.readFileByLine(Constants.getDir(this.dir, 
BLKIO_WEIGHT)).get(0)).intValue();
    +    }
    +
    +    public void setBlkioWeightDevice(Device device, int weight) throws 
IOException {
    +        CgroupUtils.writeFileByLine(Constants.getDir(this.dir, 
BLKIO_WEIGHT_DEVICE), makeContext(device, weight));
    +    }
    +
    +    public Map<Device, Integer> getBlkioWeightDevice() throws IOException {
    +        List<String> strings = 
CgroupUtils.readFileByLine(Constants.getDir(this.dir, BLKIO_WEIGHT_DEVICE));
    +        Map<Device, Integer> result = new HashMap<Device, Integer>();
    +        for (String string : strings) {
    +            String[] strArgs = string.split(" ");
    +            Device device = new Device(strArgs[0]);
    +            Integer weight = Integer.valueOf(strArgs[1]);
    +            result.put(device, weight);
    +        }
    +        return result;
    +    }
    +
    +    public void setReadBps(Device device, long bps) throws IOException {
    +        CgroupUtils.writeFileByLine(Constants.getDir(this.dir, 
BLKIO_THROTTLE_READ_BPS_DEVICE), makeContext(device, bps));
    +    }
    +
    +    public Map<Device, Long> getReadBps() throws IOException {
    +        List<String> strings = 
CgroupUtils.readFileByLine(Constants.getDir(this.dir, 
BLKIO_THROTTLE_READ_BPS_DEVICE));
    +        Map<Device, Long> result = new HashMap<Device, Long>();
    +        for (String string : strings) {
    +            String[] strArgs = string.split(" ");
    +            Device device = new Device(strArgs[0]);
    +            Long bps = Long.valueOf(strArgs[1]);
    +            result.put(device, bps);
    +        }
    +        return result;
    +    }
    +
    +    public void setWriteBps(Device device, long bps) throws IOException {
    +        CgroupUtils.writeFileByLine(Constants.getDir(this.dir, 
BLKIO_THROTTLE_WRITE_BPS_DEVICE), makeContext(device, bps));
    +    }
    +
    +    public Map<Device, Long> getWriteBps() throws IOException {
    +        List<String> strings = 
CgroupUtils.readFileByLine(Constants.getDir(this.dir, 
BLKIO_THROTTLE_WRITE_BPS_DEVICE));
    +        Map<Device, Long> result = new HashMap<Device, Long>();
    +        for (String string : strings) {
    +            String[] strArgs = string.split(" ");
    +            Device device = new Device(strArgs[0]);
    +            Long bps = Long.valueOf(strArgs[1]);
    +            result.put(device, bps);
    +        }
    +        return result;
    +    }
    +
    +    public void setReadIOps(Device device, long iops) throws IOException {
    +        CgroupUtils.writeFileByLine(Constants.getDir(this.dir, 
BLKIO_THROTTLE_READ_IOPS_DEVICE), makeContext(device, iops));
    +    }
    +
    +    public Map<Device, Long> getReadIOps() throws IOException {
    +        List<String> strings = 
CgroupUtils.readFileByLine(Constants.getDir(this.dir, 
BLKIO_THROTTLE_READ_IOPS_DEVICE));
    +        Map<Device, Long> result = new HashMap<Device, Long>();
    +        for (String string : strings) {
    +            String[] strArgs = string.split(" ");
    +            Device device = new Device(strArgs[0]);
    +            Long iops = Long.valueOf(strArgs[1]);
    +            result.put(device, iops);
    +        }
    +        return result;
    +    }
    +
    +    public void setWriteIOps(Device device, long iops) throws IOException {
    +        CgroupUtils.writeFileByLine(Constants.getDir(this.dir, 
BLKIO_THROTTLE_WRITE_IOPS_DEVICE), makeContext(device, iops));
    +    }
    +
    +    public Map<Device, Long> getWriteIOps() throws IOException {
    +        List<String> strings = 
CgroupUtils.readFileByLine(Constants.getDir(this.dir, 
BLKIO_THROTTLE_WRITE_IOPS_DEVICE));
    +        Map<Device, Long> result = new HashMap<Device, Long>();
    +        for (String string : strings) {
    +            String[] strArgs = string.split(" ");
    +            Device device = new Device(strArgs[0]);
    +            Long iops = Long.valueOf(strArgs[1]);
    +            result.put(device, iops);
    +        }
    +        return result;
    +    }
    --- End diff --
    
    `getBlkioWeightDevice`, `getReadBps`, `getWriteBps`, `getReadIOps`, 
`getWriteIOps`
    
    Don't Repeat Yourself. Same with the set versions.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to