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-2016 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 /** Standalone server. */ 035 STANDALONE, 036 /** Replicate Contents and this is the first server in topology.. */ 037 FIRST_IN_TOPOLOGY, 038 /** Replicate Contents of the new Suffix with existing server. */ 039 IN_EXISTING_TOPOLOGY 040 } 041 042 private Type type; 043 private int replicationPort = getDefaultReplicationPort(); 044 private boolean secureReplication; 045 private AuthenticationData authenticationData = new AuthenticationData(); 046 { 047 authenticationData.setDn(Constants.DIRECTORY_MANAGER_DN); 048 authenticationData.setPort(4444); 049 } 050 051 /** Private constructor for the DataReplicationOptions object. */ 052 private DataReplicationOptions() 053 { 054 } 055 056 /** 057 * Construct an FIRST_IN_TOPOLOGY object. 058 * @param replicationPort the replication port. 059 * @param secureReplication whether servers must encrypt data for the 060 * replication communication with this server. 061 * @return the FIRST_IN_TOPOLOGY object. 062 */ 063 public static DataReplicationOptions createFirstInTopology( 064 int replicationPort, boolean secureReplication) 065 { 066 DataReplicationOptions options = new DataReplicationOptions(); 067 options.type = Type.FIRST_IN_TOPOLOGY; 068 options.replicationPort = replicationPort; 069 options.secureReplication = secureReplication; 070 return options; 071 } 072 073 /** 074 * Construct an STANDALONE object. 075 * @return the STANDALONE object. 076 */ 077 public static DataReplicationOptions createStandalone() 078 { 079 DataReplicationOptions options = new DataReplicationOptions(); 080 options.type = Type.STANDALONE; 081 return options; 082 } 083 084 /** 085 * Construct an IN_EXISTING_TOPOLOGY object. 086 * @param authenticationData the authentication data. 087 * @param replicationPort the replication port. 088 * @param secureReplication whether servers must encrypt data for the 089 * replication communication with this server. 090 * @return the IN_EXISTING_TOPOLOGY object. 091 */ 092 public static DataReplicationOptions createInExistingTopology( 093 AuthenticationData authenticationData, int replicationPort, 094 boolean secureReplication) 095 { 096 DataReplicationOptions options = new DataReplicationOptions(); 097 options.type = Type.IN_EXISTING_TOPOLOGY; 098 options.authenticationData = authenticationData; 099 options.replicationPort = replicationPort; 100 options.secureReplication = secureReplication; 101 return options; 102 } 103 104 /** 105 * Returns the type of DataReplicationOptions represented by this object 106 * (replicate or not). 107 * 108 * @return the type of DataReplicationOptions. 109 */ 110 public Type getType() 111 { 112 return type; 113 } 114 115 /** 116 * Returns the AuthenticationData to the server used to replicate. 117 * If it is standalone returns null. 118 * 119 * @return the AuthenticationData to the server used to replicate. 120 */ 121 public AuthenticationData getAuthenticationData() 122 { 123 return authenticationData; 124 } 125 126 /** 127 * Returns the port that is going to be used for replication. 128 * 129 * @return the replication that must be used to configure replication. 130 */ 131 public int getReplicationPort() 132 { 133 return replicationPort; 134 } 135 136 /** 137 * Returns whether servers must encrypt data for the replication communication 138 * with this server. 139 * 140 * @return <CODE>true</CODE> if the servers must encrypt data for the 141 * replication communication and <CODE>false</CODE> otherwise. 142 */ 143 public boolean useSecureReplication() 144 { 145 return secureReplication; 146 } 147 148 /** 149 * Provides the port that will be proposed to the user in the replication 150 * options panel of the installation wizard. It will check whether we can use 151 * ports of type X989 and if not it will return -1. 152 * 153 * @return the free port of type X989 if it is available and we can use and -1 154 * if not. 155 */ 156 private static int getDefaultReplicationPort() 157 { 158 int defaultPort = -1; 159 160 for (int i=0;i<10000 && defaultPort == -1;i+=1000) 161 { 162 int port = i + Constants.DEFAULT_REPLICATION_PORT; 163 if (Utils.canUseAsPort(port)) 164 { 165 defaultPort = port; 166 } 167 } 168 return defaultPort; 169 } 170} 171