• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #9905

23 Aug 2023 06:20AM UTC coverage: 47.785% (-0.1%) from 47.922%
#9905

push

travis_ci

web-flow
[To rel/1.2][Metric] Fix flush point statistics (#10934)

23 of 23 new or added lines in 1 file covered. (100.0%)

79851 of 167106 relevant lines covered (47.78%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ModelManager.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.iotdb.confignode.manager;
21

22
import org.apache.iotdb.common.rpc.thrift.TSStatus;
23
import org.apache.iotdb.commons.model.ModelInformation;
24
import org.apache.iotdb.confignode.consensus.request.read.model.ShowModelPlan;
25
import org.apache.iotdb.confignode.consensus.request.read.model.ShowTrailPlan;
26
import org.apache.iotdb.confignode.consensus.request.write.model.UpdateModelInfoPlan;
27
import org.apache.iotdb.confignode.consensus.request.write.model.UpdateModelStatePlan;
28
import org.apache.iotdb.confignode.consensus.response.ModelTableResp;
29
import org.apache.iotdb.confignode.consensus.response.TrailTableResp;
30
import org.apache.iotdb.confignode.persistence.ModelInfo;
31
import org.apache.iotdb.confignode.rpc.thrift.TCreateModelReq;
32
import org.apache.iotdb.confignode.rpc.thrift.TDropModelReq;
33
import org.apache.iotdb.confignode.rpc.thrift.TShowModelReq;
34
import org.apache.iotdb.confignode.rpc.thrift.TShowModelResp;
35
import org.apache.iotdb.confignode.rpc.thrift.TShowTrailReq;
36
import org.apache.iotdb.confignode.rpc.thrift.TShowTrailResp;
37
import org.apache.iotdb.confignode.rpc.thrift.TUpdateModelInfoReq;
38
import org.apache.iotdb.confignode.rpc.thrift.TUpdateModelStateReq;
39
import org.apache.iotdb.consensus.common.DataSet;
40
import org.apache.iotdb.consensus.exception.ConsensusException;
41
import org.apache.iotdb.rpc.TSStatusCode;
42

43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

46
import java.io.IOException;
47
import java.util.Collections;
48

49
public class ModelManager {
50

51
  private static final Logger LOGGER = LoggerFactory.getLogger(ModelManager.class);
×
52

53
  private final ConfigManager configManager;
54
  private final ModelInfo modelInfo;
55

56
  public ModelManager(ConfigManager configManager, ModelInfo modelInfo) {
×
57
    this.configManager = configManager;
×
58
    this.modelInfo = modelInfo;
×
59
  }
×
60

61
  public ModelInfo getModelInfo() {
62
    return modelInfo;
×
63
  }
64

65
  public TSStatus createModel(TCreateModelReq req) {
66
    ModelInformation modelInformation =
×
67
        new ModelInformation(
68
            req.getModelId(),
×
69
            req.getModelTask(),
×
70
            req.getModelType(),
×
71
            req.isIsAuto(),
×
72
            req.getQueryExpressions(),
×
73
            req.getQueryFilter());
×
74
    return configManager.getProcedureManager().createModel(modelInformation, req.getModelConfigs());
×
75
  }
76

77
  public TSStatus dropModel(TDropModelReq req) {
78
    return configManager.getProcedureManager().dropModel(req.getModelId());
×
79
  }
80

81
  public TSStatus updateModelInfo(TUpdateModelInfoReq req) {
82
    try {
83
      return configManager.getConsensusManager().write(new UpdateModelInfoPlan(req));
×
84
    } catch (ConsensusException e) {
×
85
      LOGGER.warn(
×
86
          String.format("Unexpected error happened while updating model %s: ", req.getModelId()),
×
87
          e);
88
      // consensus layer related errors
89
      TSStatus res = new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
×
90
      res.setMessage(e.getMessage());
×
91
      return res;
×
92
    }
93
  }
94

95
  public TSStatus updateModelState(TUpdateModelStateReq req) {
96
    try {
97
      return configManager.getConsensusManager().write(new UpdateModelStatePlan(req));
×
98
    } catch (ConsensusException e) {
×
99
      LOGGER.warn(
×
100
          String.format(
×
101
              "Unexpected error happened while updating state of model %s: ", req.getModelId()),
×
102
          e);
103
      // consensus layer related errors
104
      TSStatus res = new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
×
105
      res.setMessage(e.getMessage());
×
106
      return res;
×
107
    }
108
  }
109

110
  public TShowModelResp showModel(TShowModelReq req) {
111
    try {
112
      DataSet response = configManager.getConsensusManager().read(new ShowModelPlan(req));
×
113
      return ((ModelTableResp) response).convertToThriftResponse();
×
114
    } catch (ConsensusException e) {
×
115
      LOGGER.warn(
×
116
          String.format("Unexpected error happened while showing model %s: ", req.getModelId()), e);
×
117
      // consensus layer related errors
118
      TSStatus res = new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
×
119
      res.setMessage(e.getMessage());
×
120
      return new TShowModelResp(res, Collections.emptyList());
×
121
    } catch (IOException e) {
×
122
      LOGGER.error("Fail to get ModelTable", e);
×
123
      return new TShowModelResp(
×
124
          new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode())
×
125
              .setMessage(e.getMessage()),
×
126
          Collections.emptyList());
×
127
    }
128
  }
129

130
  public TShowTrailResp showTrail(TShowTrailReq req) {
131
    try {
132
      DataSet response = configManager.getConsensusManager().read(new ShowTrailPlan(req));
×
133
      return ((TrailTableResp) response).convertToThriftResponse();
×
134
    } catch (ConsensusException e) {
×
135
      LOGGER.warn(
×
136
          String.format("Unexpected error happened while showing trail %s: ", req.getModelId()), e);
×
137
      // consensus layer related errors
138
      TSStatus res = new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
×
139
      res.setMessage(e.getMessage());
×
140
      return new TShowTrailResp(res, Collections.emptyList());
×
141
    } catch (IOException e) {
×
142
      LOGGER.error("Fail to get TrailTable", e);
×
143
      return new TShowTrailResp(
×
144
          new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode())
×
145
              .setMessage(e.getMessage()),
×
146
          Collections.emptyList());
×
147
    }
148
  }
149
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc