View Javadoc

1   package org.apache.helix.controller.stages;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Map;
23  
24  import org.apache.helix.HelixManager;
25  import org.apache.helix.HelixManagerProperties;
26  import org.apache.helix.controller.pipeline.AbstractBaseStage;
27  import org.apache.helix.controller.pipeline.StageException;
28  import org.apache.helix.model.LiveInstance;
29  import org.apache.log4j.Logger;
30  
31  /**
32   * controller checks if participant version is compatible 
33   *
34   */
35  public class CompatibilityCheckStage extends AbstractBaseStage {
36    private static final Logger LOG = Logger
37        .getLogger(CompatibilityCheckStage.class.getName());
38  
39    @Override
40    public void process(ClusterEvent event) throws Exception
41    {
42      HelixManager manager = event.getAttribute("helixmanager");
43      ClusterDataCache cache = event.getAttribute("ClusterDataCache");
44      if (manager == null || cache == null)
45      {
46        throw new StageException("Missing attributes in event:" + event
47            + ". Requires HelixManager | DataCache");
48      }
49  
50      HelixManagerProperties properties = manager.getProperties();
51      Map<String, LiveInstance> liveInstanceMap = cache.getLiveInstances();
52      for (LiveInstance liveInstance : liveInstanceMap.values())
53      {
54        String participantVersion = liveInstance.getHelixVersion();
55        if (!properties.isParticipantCompatible(participantVersion))
56        {
57          String errorMsg = "incompatible participant. pipeline will not continue. "
58                          + "controller: " + manager.getInstanceName() 
59                          + ", controllerVersion: " + properties.getVersion()
60                          + ", minimumSupportedParticipantVersion: " 
61                          + properties.getProperty("miminum_supported_version.participant")
62                          + ", participant: " + liveInstance.getInstanceName() 
63                          + ", participantVersion: " + participantVersion;
64          LOG.error(errorMsg);
65          throw new StageException(errorMsg);
66        }
67      }
68    }
69  }