@@ -183,11 +183,10 @@ public static boolean existTenantCodeInLinux(String tenantCode) {
183183 *
184184 * @param userName user name
185185 */
186- public static void createUserIfAbsent (String userName ) {
186+ public static synchronized void createUserIfAbsent (String userName ) {
187187 // if not exists this user, then create
188188 if (!getUserList ().contains (userName )) {
189- boolean isSuccess = createUser (userName );
190- log .info ("create user {} {}" , userName , isSuccess ? "success" : "fail" );
189+ createUser (userName );
191190 }
192191 }
193192
@@ -197,13 +196,12 @@ public static void createUserIfAbsent(String userName) {
197196 * @param userName user name
198197 * @return true if creation was successful, otherwise false
199198 */
200- public static boolean createUser (String userName ) {
199+ public static void createUser (String userName ) {
201200 try {
202201 String userGroup = getGroup ();
203202 if (StringUtils .isEmpty (userGroup )) {
204- String errorLog = String .format ("%s group does not exist for this operating system." , userGroup );
205- log .error (errorLog );
206- return false ;
203+ throw new UnsupportedOperationException (
204+ "There is no userGroup exist cannot create tenant, please create userGroupFirst" );
207205 }
208206 if (SystemUtils .IS_OS_MAC ) {
209207 createMacUser (userName , userGroup );
@@ -212,18 +210,17 @@ public static boolean createUser(String userName) {
212210 } else {
213211 createLinuxUser (userName , userGroup );
214212 }
215- return true ;
213+ log . info ( "Create tenant {} under userGroup: {} success" , userName , userGroup ) ;
216214 } catch (Exception e ) {
217- log . error ( e . getMessage () , e );
215+ throw new RuntimeException ( "Create tenant: {} failed" , e );
218216 }
219217
220- return false ;
221218 }
222219
223220 /**
224221 * create linux user
225222 *
226- * @param userName user name
223+ * @param userName user name
227224 * @param userGroup user group
228225 * @throws IOException in case of an I/O error
229226 */
@@ -237,7 +234,7 @@ private static void createLinuxUser(String userName, String userGroup) throws IO
237234 /**
238235 * create mac user (Supports Mac OSX 10.10+)
239236 *
240- * @param userName user name
237+ * @param userName user name
241238 * @param userGroup user group
242239 * @throws IOException in case of an I/O error
243240 */
@@ -256,7 +253,7 @@ private static void createMacUser(String userName, String userGroup) throws IOEx
256253 /**
257254 * create windows user
258255 *
259- * @param userName user name
256+ * @param userName user name
260257 * @param userGroup user group
261258 * @throws IOException in case of an I/O error
262259 */
@@ -304,7 +301,7 @@ public static String getGroup() throws IOException {
304301 * get sudo command
305302 *
306303 * @param tenantCode tenantCode
307- * @param command command
304+ * @param command command
308305 * @return result of sudo execute command
309306 */
310307 public static String getSudoCmd (String tenantCode , String command ) {
0 commit comments