001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2006-2008 Sun Microsystems, Inc. 015 * Portions Copyright 2013-2015 ForgeRock AS. 016 */ 017package org.opends.quicksetup.installer; 018 019import org.opends.quicksetup.Constants; 020import org.opends.quicksetup.util.Utils; 021 022/** 023 * This class is used to provide a data model for the Data Replication 024 * Options panel of the installer. 025 */ 026public class DataReplicationOptions 027{ 028 /** 029 * This enumeration is used to know what the user wants to do for the data 030 * (import data or not, what use as source of the data...). 031 */ 032 public enum Type 033 { 034 /** 035 * Standalone server. 036 */ 037 STANDALONE, 038 /** 039 * Replicate Contents and this is the first server in topology.. 040 */ 041 FIRST_IN_TOPOLOGY, 042 /** 043 * Replicate Contents of the new Suffix with existing server. 044 */ 045 IN_EXISTING_TOPOLOGY 046 } 047 048 private Type type; 049 private int replicationPort = getDefaultReplicationPort(); 050 private boolean secureReplication; 051 private AuthenticationData authenticationData = new AuthenticationData(); 052 { 053 authenticationData.setDn(Constants.DIRECTORY_MANAGER_DN); 054 authenticationData.setPort(4444); 055 } 056 057 /** 058 * Private constructor for the DataReplicationOptions object. 059 */ 060 private DataReplicationOptions() 061 { 062 } 063 064 /** 065 * Construct an FIRST_IN_TOPOLOGY object. 066 * @param replicationPort the replication port. 067 * @param secureReplication whether servers must encrypt data for the 068 * replication communication with this server. 069 * @return the FIRST_IN_TOPOLOGY object. 070 */ 071 public static DataReplicationOptions createFirstInTopology( 072 int replicationPort, boolean secureReplication) 073 { 074 DataReplicationOptions options = new DataReplicationOptions(); 075 options.type = Type.FIRST_IN_TOPOLOGY; 076 options.replicationPort = replicationPort; 077 options.secureReplication = secureReplication; 078 return options; 079 } 080 081 /** 082 * Construct an STANDALONE object. 083 * @return the STANDALONE object. 084 */ 085 public static DataReplicationOptions createStandalone() 086 { 087 DataReplicationOptions options = new DataReplicationOptions(); 088 options.type = Type.STANDALONE; 089 return options; 090 } 091 092 /** 093 * Construct an IN_EXISTING_TOPOLOGY object. 094 * @param authenticationData the authentication data. 095 * @param replicationPort the replication port. 096 * @param secureReplication whether servers must encrypt data for the 097 * replication communication with this server. 098 * @return the IN_EXISTING_TOPOLOGY object. 099 */ 100 public static DataReplicationOptions createInExistingTopology( 101 AuthenticationData authenticationData, int replicationPort, 102 boolean secureReplication) 103 { 104 DataReplicationOptions options = new DataReplicationOptions(); 105 options.type = Type.IN_EXISTING_TOPOLOGY; 106 options.authenticationData = authenticationData; 107 options.replicationPort = replicationPort; 108 options.secureReplication = secureReplication; 109 return options; 110 } 111 112 /** 113 * Returns the type of DataReplicationOptions represented by this object 114 * (replicate or not). 115 * 116 * @return the type of DataReplicationOptions. 117 */ 118 public Type getType() 119 { 120 return type; 121 } 122 123 /** 124 * Returns the AuthenticationData to the server used to replicate. 125 * If it is standalone returns null. 126 * 127 * @return the AuthenticationData to the server used to replicate. 128 */ 129 public AuthenticationData getAuthenticationData() 130 { 131 return authenticationData; 132 } 133 134 /** 135 * Returns the port that is going to be used for replication. 136 * 137 * @return the replication that must be used to configure replication. 138 */ 139 public int getReplicationPort() 140 { 141 return replicationPort; 142 } 143 144 /** 145 * Returns whether servers must encrypt data for the replication communication 146 * with this server. 147 * 148 * @return <CODE>true</CODE> if the servers must encrypt data for the 149 * replication communication and <CODE>false</CODE> otherwise. 150 */ 151 public boolean useSecureReplication() 152 { 153 return secureReplication; 154 } 155 156 /** 157 * Provides the port that will be proposed to the user in the replication 158 * options panel of the installation wizard. It will check whether we can use 159 * ports of type X989 and if not it will return -1. 160 * 161 * @return the free port of type X989 if it is available and we can use and -1 162 * if not. 163 */ 164 static int getDefaultReplicationPort() 165 { 166 int defaultPort = -1; 167 168 for (int i=0;i<10000 && defaultPort == -1;i+=1000) 169 { 170 int port = i + Constants.DEFAULT_REPLICATION_PORT; 171 if (Utils.canUseAsPort(port)) 172 { 173 defaultPort = port; 174 } 175 } 176 return defaultPort; 177 } 178} 179