Skip to content

Commit 29b0bf5

Browse files
committed
IGNITE-26748 Add commands for control.sh
1 parent 2017e43 commit 29b0bf5

File tree

11 files changed

+431
-0
lines changed

11 files changed

+431
-0
lines changed

modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/CommandHandlerParsingTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.apache.ignite.internal.management.metric.MetricCommand;
7777
import org.apache.ignite.internal.management.performancestatistics.PerformanceStatisticsCommand;
7878
import org.apache.ignite.internal.management.property.PropertyCommand;
79+
import org.apache.ignite.internal.management.rollingupgrade.RollingUpgradeCommand;
7980
import org.apache.ignite.internal.management.snapshot.SnapshotCommand;
8081
import org.apache.ignite.internal.management.snapshot.SnapshotRestoreCommand;
8182
import org.apache.ignite.internal.management.tx.TxCommand;
@@ -1391,6 +1392,7 @@ private boolean requireArgs(Class<?> cmd) {
13911392
cmd == MetaCommand.class ||
13921393
cmd == WarmUpCommand.class ||
13931394
cmd == PropertyCommand.class ||
1395+
cmd == RollingUpgradeCommand.class ||
13941396
cmd == SystemViewCommand.class ||
13951397
cmd == MetricCommand.class ||
13961398
cmd == DefragmentationCommand.class ||

modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite2.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.ignite.util.IdleVerifyDumpTest;
3838
import org.apache.ignite.util.MetricCommandTest;
3939
import org.apache.ignite.util.PerformanceStatisticsCommandTest;
40+
import org.apache.ignite.util.RollingUpgradeCommandTest;
4041
import org.apache.ignite.util.SystemViewCommandTest;
4142
import org.junit.runner.RunWith;
4243
import org.junit.runners.Suite;
@@ -63,6 +64,7 @@
6364
GridCommandHandlerConsistencySensitiveTest.class,
6465
GridCommandHandlerConsistencyRepairCorrectnessAtomicTest.class,
6566

67+
RollingUpgradeCommandTest.class,
6668
SystemViewCommandTest.class,
6769
MetricCommandTest.class,
6870
PerformanceStatisticsCommandTest.class,
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.util;
19+
20+
import org.apache.ignite.internal.management.rollingupgrade.RollingUpgradeCommand;
21+
import org.apache.ignite.lang.IgniteProductVersion;
22+
import org.junit.Test;
23+
24+
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
25+
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR;
26+
27+
/** Tests {@link RollingUpgradeCommand} command. */
28+
public class RollingUpgradeCommandTest extends GridCommandHandlerClusterByClassAbstractTest {
29+
/** */
30+
public static final String ENABLE = "enable";
31+
32+
/** */
33+
public static final String DISABLE = "disable";
34+
35+
/** */
36+
public static final String ROLLING_UPGRADE = "--rolling-upgrade";
37+
38+
/** */
39+
@Test
40+
public void testCommands() {
41+
int res = execute(ROLLING_UPGRADE, DISABLE);
42+
43+
assertEquals(EXIT_CODE_OK, res);
44+
assertEquals("Rolling upgrade disabled.", lastOperationResult);
45+
46+
IgniteProductVersion curVer = crd.version();
47+
48+
IgniteProductVersion nextVer = new IgniteProductVersion(curVer.major(),
49+
(byte)(curVer.minor() + 1),
50+
(byte)0,
51+
curVer.revisionTimestamp(),
52+
curVer.revisionHash());
53+
54+
res = execute(ROLLING_UPGRADE, ENABLE, nextVer.toString());
55+
56+
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, res);
57+
assertEquals(null, lastOperationResult);
58+
59+
res = execute(ROLLING_UPGRADE, DISABLE);
60+
61+
assertEquals(EXIT_CODE_OK, res);
62+
assertEquals("Rolling upgrade disabled.", lastOperationResult);
63+
}
64+
}

modules/core/src/main/java/org/apache/ignite/internal/management/IgniteCommandRegistry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.ignite.internal.management.performancestatistics.PerformanceStatisticsCommand;
3535
import org.apache.ignite.internal.management.persistence.PersistenceCommand;
3636
import org.apache.ignite.internal.management.property.PropertyCommand;
37+
import org.apache.ignite.internal.management.rollingupgrade.RollingUpgradeCommand;
3738
import org.apache.ignite.internal.management.snapshot.SnapshotCommand;
3839
import org.apache.ignite.internal.management.tracing.TracingConfigurationCommand;
3940
import org.apache.ignite.internal.management.tx.TxCommand;
@@ -67,6 +68,7 @@ public IgniteCommandRegistry() {
6768
new TracingConfigurationCommand(),
6869
new WarmUpCommand(),
6970
new PropertyCommand(),
71+
new RollingUpgradeCommand(),
7072
new SystemViewCommand(),
7173
new MetricCommand(),
7274
new PersistenceCommand(),
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.management.rollingupgrade;
19+
20+
import java.io.IOException;
21+
import java.io.ObjectInput;
22+
import java.io.ObjectOutput;
23+
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
24+
import org.apache.ignite.internal.management.api.Argument;
25+
import org.apache.ignite.internal.management.api.CommandRegistryImpl;
26+
import org.apache.ignite.internal.management.api.Positional;
27+
import org.apache.ignite.internal.util.typedef.internal.U;
28+
29+
/** Rolling upgrade commands. */
30+
public class RollingUpgradeCommand extends CommandRegistryImpl {
31+
/** */
32+
public RollingUpgradeCommand() {
33+
super(
34+
new RollingUpgradeEnableCommand(),
35+
new RollingUpgradeDisableCommand()
36+
);
37+
}
38+
39+
/** Base rolling upgrade command argument. */
40+
public static class RollingUpgradeCommandArg extends IgniteDataTransferObject {
41+
/** */
42+
private static final long serialVersionUID = 0;
43+
44+
/** {@inheritDoc} */
45+
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
46+
// No-op.
47+
}
48+
49+
/** {@inheritDoc} */
50+
@Override protected void readExternalData(ObjectInput in) throws IOException, ClassNotFoundException {
51+
// No-op.
52+
}
53+
}
54+
55+
/** Rolling upgrade enable command argument. */
56+
public static class RollingUpgradeEnableCommandArg extends RollingUpgradeCommandArg {
57+
/** */
58+
private static final long serialVersionUID = 0;
59+
60+
/** Target version. */
61+
@Argument(description = "Target Ignite version", example = "2.18.0")
62+
@Positional
63+
private String targetVersion;
64+
65+
/** */
66+
public String targetVersion() {
67+
return targetVersion;
68+
}
69+
70+
/** */
71+
public void targetVersion(String targetVersion) {
72+
this.targetVersion = targetVersion;
73+
}
74+
75+
/** {@inheritDoc} */
76+
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
77+
super.writeExternalData(out);
78+
79+
U.writeString(out, targetVersion);
80+
}
81+
82+
/** {@inheritDoc} */
83+
@Override protected void readExternalData(ObjectInput in) throws IOException, ClassNotFoundException {
84+
super.readExternalData(in);
85+
86+
targetVersion = U.readString(in);
87+
}
88+
}
89+
90+
/** Rolling upgrade disable command argument. */
91+
public static class RollingUpgradeDisableCommandArg extends RollingUpgradeCommandArg {
92+
/** */
93+
private static final long serialVersionUID = 0;
94+
}
95+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.management.rollingupgrade;
19+
20+
import java.util.Collection;
21+
import org.apache.ignite.cluster.ClusterNode;
22+
import org.apache.ignite.internal.management.api.ComputeCommand;
23+
import org.apache.ignite.internal.management.rollingupgrade.RollingUpgradeCommand.RollingUpgradeDisableCommandArg;
24+
25+
import static org.apache.ignite.internal.management.api.CommandUtils.coordinatorOrNull;
26+
import static org.apache.ignite.internal.management.rollingupgrade.RollingUpgradeCommand.RollingUpgradeCommandArg;
27+
28+
/** Command to disable rolling upgrade mode. */
29+
public class RollingUpgradeDisableCommand implements ComputeCommand<RollingUpgradeCommandArg, String> {
30+
/** {@inheritDoc} */
31+
@Override public String description() {
32+
return "Disable rolling upgrade";
33+
}
34+
35+
/** {@inheritDoc} */
36+
@Override public Class<RollingUpgradeDisableCommandArg> argClass() {
37+
return RollingUpgradeDisableCommandArg.class;
38+
}
39+
40+
/** {@inheritDoc} */
41+
@Override public Class<RollingUpgradeTask> taskClass() {
42+
return RollingUpgradeTask.class;
43+
}
44+
45+
/** {@inheritDoc} */
46+
@Override public Collection<ClusterNode> nodes(Collection<ClusterNode> nodes, RollingUpgradeCommandArg arg) {
47+
return coordinatorOrNull(nodes);
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.management.rollingupgrade;
19+
20+
import java.util.Collection;
21+
import org.apache.ignite.cluster.ClusterNode;
22+
import org.apache.ignite.internal.management.api.ComputeCommand;
23+
import org.apache.ignite.internal.management.rollingupgrade.RollingUpgradeCommand.RollingUpgradeEnableCommandArg;
24+
25+
import static org.apache.ignite.internal.management.api.CommandUtils.coordinatorOrNull;
26+
import static org.apache.ignite.internal.management.rollingupgrade.RollingUpgradeCommand.RollingUpgradeCommandArg;
27+
28+
/** Command to enable rolling upgrade. */
29+
public class RollingUpgradeEnableCommand implements ComputeCommand<RollingUpgradeCommandArg, String> {
30+
/** {@inheritDoc} */
31+
@Override public String description() {
32+
return "Enable rolling upgrade";
33+
}
34+
35+
/** {@inheritDoc} */
36+
@Override public Class<RollingUpgradeEnableCommandArg> argClass() {
37+
return RollingUpgradeEnableCommandArg.class;
38+
}
39+
40+
/** {@inheritDoc} */
41+
@Override public Class<RollingUpgradeTask> taskClass() {
42+
return RollingUpgradeTask.class;
43+
}
44+
45+
/** {@inheritDoc} */
46+
@Override public Collection<ClusterNode> nodes(Collection<ClusterNode> nodes, RollingUpgradeCommandArg arg) {
47+
return coordinatorOrNull(nodes);
48+
}
49+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.management.rollingupgrade;
19+
20+
import java.io.IOException;
21+
import java.io.ObjectInput;
22+
import java.io.ObjectOutput;
23+
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
24+
import org.apache.ignite.internal.management.api.Argument;
25+
import org.apache.ignite.internal.management.api.Positional;
26+
import org.apache.ignite.internal.util.typedef.internal.U;
27+
28+
/** */
29+
public class RollingUpgradeEnableCommandArg extends IgniteDataTransferObject {
30+
/** */
31+
private static final long serialVersionUID = 0;
32+
33+
/** */
34+
@Argument(description = "Enable rollong upgrade")
35+
@Positional
36+
private String ver;
37+
38+
/** {@inheritDoc} */
39+
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
40+
U.writeString(out, ver);
41+
}
42+
43+
/** {@inheritDoc} */
44+
@Override protected void readExternalData(ObjectInput in) throws IOException, ClassNotFoundException {
45+
ver = U.readString(in);
46+
}
47+
48+
/** */
49+
public String ver() {
50+
return ver;
51+
}
52+
53+
/** */
54+
public void ver(String ver) {
55+
this.ver = ver;
56+
}
57+
}

0 commit comments

Comments
 (0)